1

I have a section in my footer from a script, that I am trying to customize and that displays the website categories.

Currently the results were limited to 9 results per column and continuing onto x amounts of columns. I need to be able to stop at 2 columns.

Here is the code I have

<div class="left">
    <h3 style="padding-top:15px;"><?php echo BROWSE_CATEGORIES; ?></h3>
    <?php $footer_category= $this->home_model->get_category(); ?>
    <?php if($footer_category) { $ftr_cnt=1; ?>
    <ul>
        <?php foreach($footer_category as $cat) { 
            echo '<li>'.anchor('search/category/'.$cat->project_category_id,substr($cat->project_category_name,0,30)).'</li>'; 

            if($ftr_cnt>9) { $ftr_cnt=1; echo "</ul><ul>";  }
                $ftr_cnt++;
            }
        } ?>
    </ul>
</div>
1
  • is there any reason that you can't change $ftr_cnt>9 to $ftr_ctn>2? Commented Sep 28, 2012 at 7:28

1 Answer 1

2

Use a break when you've reached 9 * 2, where 2 is the amount of columns you want.

$ftr_cnt = 1;
foreach($footer_category as $cat) 
{ 
    echo '<li>'.anchor('search/category/'.$cat->project_category_id,substr($cat->project_category_name,0,30)).'</li>'; 
    if($ftr_cnt == 9) 
    { 
        echo "</ul><ul>";  
    } 

    $ftr_cnt++;

    if($ftr_cnt >= (9 * 2))
    {
        echo "</ul>";
        break;
    }
} 
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your input. No matter how i insert this it breaks the page ;( all i get is a blank page.
@Shadowtek, can you check your error logs? I don't see an error right now. Maybe there is a conflict somewhere?
@Shadowtek try to debug a bit, remove some parts until you get it working again, then you should know what the problem is. For instance, try removing the anchor and replacing it with just some text.
Rune Thank you once again for your help, i have managed to get the code in with out the page breaking however it has has no effect. I will keep trying :)
@Shadowtek try to echo every $ftr_cnt after increasing it. Then do an echo in both if statements. If everything echoes correctly then it's something with that anchor part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.