WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[Plugin: WordPress Popular Posts] Suggested feature (with code): cats_to_include (10 posts)

  1. audvin
    Member
    Posted 2 years ago #

    I've wanted this feature myself and have modified the wordpress-popular-posts.php file to make it happen. Perhaps you would consider to implement this in the release.

    Code to add to wordpress-popular-posts.php:

    Before line 623:

    if ( $instance['include-cats']['active'] && !empty($instance['include-cats']['cats']) ) {
    				$exclude = " AND $wpdb->posts.ID IN (
    
    							SELECT  object_id
    							FROM    $wpdb->term_relationships AS r
    									JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
    									JOIN $wpdb->terms AS t ON t.term_id = x.term_id
    							WHERE   x.taxonomy = 'category'
    									AND object_id IN
    									   (
    										SELECT object_id
    										FROM $wpdb->term_relationships AS r
    										JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
    										JOIN $wpdb->terms AS t ON t.term_id = x.term_id
    										WHERE   x.taxonomy = 'category'
    										AND t.term_id IN  (".$instance['include-cats']['cats']."))) ";
    			} else {
    				$exclude = "";
    			}

    Before line 1020:

    'cats_to_include' => '',

    Before line 1062:

    ),
    				'include-cats' => array(
    					'active' => empty($cats_to_include) ? false : (ctype_digit(str_replace(",", "", $cats_to_include))) ? true : false,
    					'cats' => empty($cats_to_include) ? '' : (ctype_digit(str_replace(",", "", $cats_to_include))) ? $cats_to_include : ''
    				),

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks audvin,

    I'm assuming that this code is executed only when the Exclude Category functionality is not in use, right?

    Also, althought it might sound obvious, could you please illustrate a case where this feature is needed?

  3. audvin
    Member
    Posted 2 years ago #

    Yes, however I have not tested it in a case where someone may accidentally use both exclude and include calls.

    I have many categories, it's far easier to say which one I want to list stats for and not list all those I do not wish to list for :)

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    I see. So, if someone is checking a Category page then my plugin should show only the popular entries related to it. Am I right?

  5. audvin
    Member
    Posted 2 years ago #

    Yes, that's correct. You will get stats per category basis. That's what I use it for.

  6. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    What if my plugin did this: whenever someone enters yoursite.com/category/ WPP would build the list of popular posts automatically with entries related to that specific category? Or maybe it'd be better to let users decide what category to show on the sidebar? Or both?

  7. audvin
    Member
    Posted 2 years ago #

    Sounds good. I use the this plugin in a special page template, calling the php. That's how I came to need this functionality.

  8. Misha G.
    Member
    Posted 2 years ago #

    First off, I'd like to say thank you for a great plugin!

    I completely agree with audvin and have the same exact issue. I have very large sites with many categories. I call the get_mostpopular() function in php for select category pages AND all posts within those categories; My get_mostpopular() calls are almost unmanageable at this point and it would be fantastic if you were to consider adding some sort of an "include" functionality.

    Anyway, I propose that you rename "exclude-cats" parameter to "filter-cats" and add another parameter called "filter-style" with 2 possible values: "exclude" or "include". This would eliminate the case where someone may accidentally use both exclude and include calls.

    Widgets are for AOL users :)

    Ragards,
    Misha

  9. Damien Saunders
    Member
    Posted 2 years ago #

    I really like this too .. I've been waiting for this plugin to have 'include categories'

    If you need any one to test this please let me know :)

    BUT I'd like this to be a multi-widget so that I can use it on my home page, footers or other widget areas

  10. Héctor Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Hi Damien,

    My plugin is already multi-widget capable, you can use it anywhere on your theme.

    As for the cats-to-include suggestion, it's already on my TODO list. Any further suggestions are welcome!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic