WordPress.org

Ready to get started?Download WordPress

Forums

Limiting categories on homepage (4 posts)

  1. kateh12
    Member
    Posted 1 year ago #

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

    http://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?

  2. Jerry
    Member
    Posted 1 year ago #

    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.

  3. kateh12
    Member
    Posted 1 year ago #

    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!

  4. Jerry
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic