• I’m working on a site using the Suburbia theme and really want to limit the number of categories listed on the homepage only.

    https://www.mapleleafmamma.com/

    As you can see, it starts to look sloppy on the two featured posts with more than one or two categories listed. How can I limit the number displayed on the homepage?

Viewing 3 replies - 1 through 3 (of 3 total)
  • On your sidebar.php file in the theme files you have this.

    <ul>
            <?php wp_list_categories('show_count=1&title_li='); ?>
            </ul>

    Change it to this

    <ul>
            <?php if(is_home()): ?>
            	<?php wp_list_categories('show_count=1&number=5&title_li='); ?>
            <?php else: ?>
            	<?php wp_list_categories('show_count=1&title_li='); ?>
            <?php endif; ?>
            </ul>

    Your categories uses the wp_list_categories() function that has tons of options. In the first statement I simply added the “number=5” you can change that to what works for you.

    The is_home() function first checks if you’re on the home page, if so it’ll run the first list categories, if not, it’ll run the other one without the number argument.

    Thread Starter kateh12

    (@kateh12)

    Sorry for the confusion, it’s not the sidebar where I want to limit them…it’s in the top two featured/big posts. Where it lists the date of the post and then “in” <categories>. When they get bumped to the second line line it looks messy.

    Thanks!

    Ahh, in that case you’d have to do a custom loop of get_the_category() I don’t really have time to show you how, but did provide a link, maybe that will get you started.

    Additionally you’ll have to look at the home.php file and take note of the “the_category” calls in the loop 1 and loop 2 blocks. That’s what you’ll have to change.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limiting categories on homepage’ is closed to new replies.