Support » Plugin: WordPress Popular Posts » [Plugin: WordPress Popular Posts] Need to limit category for non-widget use

  • Resolved cerulean


    I’m using WPP within a series of sidebar tabs and need to limit what pages appear. For one, Home appears as a top result. There are also a couple of categories I’d like to exclude. Below is what I have so far. Please let me know what I can add to allow for removal of certain category / page IDs. Thanks!

    <?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular('stats_comments=0 & range=all & order_by=all & limit=8'); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi cerulean,

    You need to use the cats_to_exclude parameter to specify which categories you wish to have excluded, like this:

    if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular('stats_comments=0&range=all&order_by=comments&limit=8&cats_to_exclude=1,5,33');

    For a more complete list of available paramaters and its usage please go to your wp-admin > Settings > WordPress Popular Posts page.

    P.S.: the order_by parameter only accepts the following values: comments, views, avg. Make sure you use the right ones or my plugin will automatically switch to the default values.

    This is great info, thanks for the timely response. The only thing that’s still showing up as popular is Home which is a page (and not a post with an assigned category). How can I exclude this specific page from the results?

    Unfortunately, there’s no way to achieve this with the current version of my plugin. You’ll have to hack through the code of my plugin to do this.

    Open wordpress-popular-posts.php using an editor such as Windows’ Notepad or Adobe Dreamweaver, and change this code (around line 608):

    $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $exclude GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");

    … into this:

    $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $exclude AND $wpdb->posts.ID NOT IN(15) GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");

    … where AND $wpdb->posts.ID NOT IN(15) specifies the ID of the page(s) you want to exclude (in your case, it should be the ID of the home page).

    That worked beautifully, except for hacking up your great plugin : )

    Thanks for your help (and very clear explanations!)

    You’re welcome! I might include a page/post excluding feature on a future release of my plugin to make this more simple and keep people from having to hack my plugin 😛

    Thank you for your words!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: WordPress Popular Posts] Need to limit category for non-widget use’ is closed to new replies.