• Resolved Mike Lee

    (@mikeleeorg)


    I am working on a site that has 4 major (parent) categories and numerous sub (child) categories under those 4. In one of those parent categories, I need to display the top posts from just that category.

    I realize I can exclude all of the other categories, but unfortunately, I cannot simply exclude a parent category – I would have to exclude all of the child categories one by one. For this site, new child categories are created fairy often, so this would not be a scalable solution.

    Is there another solution, short of modifying the plugin’s code directly (which I really do not want to do) and hoping a future update has this feature? And will a future update have a feature like this? If the plugin author is collecting votes, I certainly vote on this feature!

    Thanks.

    https://wordpress.org/plugins/top-10/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Mike Lee

    (@mikeleeorg)

    FYI, here is a simple change that does offer this functionality, though I really don’t want to be modifying this plugin’s code since it will cause update problems. But in case someone else has this problem, or the plugin author is reading this and is interested in suggestions, here is an option:

    In file top-10.php, line 408, change it from:

    $p_in_c = (in_array($cat->cat_ID, $exclude_categories)) ? true : false;

    to:

    $p_in_c = (in_array($cat->cat_ID, $exclude_categories) || in_array($cat->parent, $exclude_categories)) ? true : false;

    Plugin Author Ajay

    (@ajay)

    Hi,

    If I understand correctly, then this code will exclude the display on a category as well as its parent categories?

    Thread Starter Mike Lee

    (@mikeleeorg)

    Yup, correct. in_array($cat->parent, $exclude_categories) checks to see if the category’s parent is listed in the exclude_categories array.

    This wouldn’t go any higher up the category hierarchy though. For instance, if someone had 3 or more levels of child categories, doing this would only climb up one level.

    If you would like to offer the ability to exclude an entire parent category and all of its children, you could look into using the custom post_is_in_descendant_category function listed in the WP Codex:
    http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category

    And thanks for putting out such a great plugin too!

    Plugin Author Ajay

    (@ajay)

    You’re welcome and thanks for the code. This will ofcourse not be the default feature since that would not work for every users requirements.

    But, I can add this as an optional feature for all users.

    Thread Starter Mike Lee

    (@mikeleeorg)

    Thanks! If at all possible, I would love to see this in the next release 😉

    In any case, I’ll mark this topic as resolved.

    Plugin Author Ajay

    (@ajay)

    Will put this on the list to add.

    I don’t know if this is what i was needing or not but i wanted a way to filter the top posts by category, like show Top Posts overall but not from the whole blog but for certain category, this filter could be added on the widget as a drop-down menu.
    If this isn’t it, then consider for next updates maybe.

    Cheers.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display top posts within specific categories or sub-categories?’ is closed to new replies.