• On the side of my blog atm, it displays every category that i have. it uses this

      <?php wp_list_cats(); ?>

    How can i make it display the top 10 or so most common categories, rather than all of them.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Top 10 alphabetically? popularity? ones you want displayed? “Most common” isn’t really clear.

    Here’s what the Codex says:
    https://codex.www.ads-software.com/Template_Tags/wp_list_cats

    You could work with excluding certain categories from the list. If you have 20 categories and only want to list the first 10:
    <ul>
    <?php wp_list_cats('sort_column=name&optioncount=1&exclude=11, 12, 13, 14, 15, 16, 17, 18, 19, 20'); ?>
    </ul>

    Thread Starter matkinsblog

    (@matkinsblog)

    by most common i meant popularity of posts in that category, ie, 5 posts under news, 4 posts in humour

    So you want to only display the, say, top 10 categories by the amount of posts you have in the category? I’ll be interested to see what others say to this. I don’t know of a way to do it, but it’s probably possible.

    How does this function grab the number of posts in a category? Could a plugin write that number to a temporary table? Then that could be a variable that is the number of posts in a category. Maybe there’s a way to compare those numbers and only take number C if it’s higher than number D. If we could add the number of posts in a category to sort_column and add something like sort_limit to only display a certain number of categories.

    This might be a place to start:
    https://businesslogs.com/business_logs/reboot_launch_business_logs.php

    Thread Starter matkinsblog

    (@matkinsblog)

    no one?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Most Common Categories In Sidebar’ is closed to new replies.