WordPress.org

Ready to get started?Download WordPress

Forums

Show some categories based on number of posts (2 posts)

  1. CirceTheHouseCat
    Member
    Posted 1 year ago #

    Hi everyone, this is my first question here. I am a little lost, because what I am trying to achieve in my site is to show on the sidebar only certains categories, based on the numbers of post in that specific category (no entry is posted in more the one category). For instance, I would like to be able to show only categories that have at least 10 post.

    I've searched and founded this thread: http://wordpress.org/support/topic/exclude-multiple-categories-from-home-page-2, but:

    1) is an old one
    2) doesn't really fit me, as only refers on how to exclude categories based on ID
    3) I have a vague idea of php, so I guess what I'll need would be a tutorial or something similar

    Can any of you suggest me some resource where I can find a clue or give me some tips on how to achieve this?

    Thank you in advance for your time, and as we are close... happy new year!

    Cheers from Spain!

  2. bcworkz
    Member
    Posted 1 year ago #

    I don't know of a step by step, but hopefully this will help. You want to use get categories. See if you can do something with the examples, in particular the one that lists categories with descriptions. It also lists the post counts for each category.

    You variant of this would simply only echo out the html for any category if the $category->count > 9, something like

    $categories=get_categories();
      foreach($categories as $category) {
        if ($category->count > 9) {
          //echo stuff as in example
        }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic