WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
Top Post in category (19 posts)

  1. andy999
    Member
    Posted 1 year ago #

    I'm making a multi author WordPress site in which authors can create their own categories as they see fit.

    I have a left sidebar with the top 20 OVERALL most popular posts and on each category page I'd like to have the top 5 post in that category alone.

    As I understand it you can use the cat-ID to do this, the problem is I don't think its practical to do this manually.
    Is there a way to put this on my category.php template page and have it automatically grab the top 5 posts from the current category that the user is on?

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

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Andy,

    I've been planning to add category detection to the plugin for some time now, the cat-ID parameter is an early step to achieve that.

  3. andy999
    Member
    Posted 1 year ago #

    That would be awesome, Hector!

    Especially if it was dynamic and I could just add a template tag to my category.php.

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    That's the basic idea, yes ;) Will post here if I need you help testing that, alright?

  5. GK Goalla
    Member
    Posted 9 months ago #

    Hi Hector,

    I request your expertise :)

    I'm looking for a widget which can list popular posts (by views) from current category ?

    Let's say if I'm reading a post from "Finance" category then the widget on sidebar should display top 5 popular posts from the current category.

    Could you please let me know if any widget is available ?

    Thanks

  6. a4jp.com
    Member
    Posted 8 months ago #

    Does the category filter section include or exclude posts/pages? It would be cool if we could turn on check boxes as well, as it takes a long time to check and type in all the ids. I found another plugin that lists the ids in the category area though.

  7. a4jp.com
    Member
    Posted 8 months ago #

    For some reason nothing is happening on my page. The plugin just says no data. It would be nice if we could customize the no data message as well. I want English in one sidebar and Japanese in another.

  8. a4jp.com
    Member
    Posted 8 months ago #

    I found a plugin I made was blocking this plugin from working (o-O)

    Everything looks good now ^^

    It would just be nice if it was easier to add categories.

    Thank you for a great plugin.

  9. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    Hi guys, sorry for the late reply.

    @GK Goalla: no, as far as I knoe there's no plugin that can do that. I'm planning to add that feature as I said before.

    @a4jp.com: thanks for the suggestion, it's not a bad idea actually. I might implement a Category selector (or something like that) to make it easier for everyone to use this filter.

  10. andy999
    Member
    Posted 8 months ago #

    The category ID filter is somewhat useless, because we'd have to create a new template for each category we wanted to have a specific widget area for, then create a new instance of the popular posts widget for that category page.

    Be nice if we could just select 'Rank posts by category', then the plugin would know to show only the top x number of posts on any given category page, that way we wouldn't need 20 templates.

  11. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    Sorry, I'm not following. Why would you need to create new templates for each category? Doesn't make sense.

    What @a4jp.com suggested was to have the ability to select the category on the Widget form using a checkbox or something like that instead of having to type in the category ID manually.

  12. andy999
    Member
    Posted 8 months ago #

    Well, lets assume I have the plugin set up to retrieve the top 5 posts by views, I have it in my sidebar and that's repeated on each page of the site, index.php, category.php, single.php etc.
    It'll always be getting the top 5 posts, regardless of where you are.

    Now, there's an option in the plugin (perhaps I'm understanding this wrong) where you can get specific category ID's, so lets say the category 'web development' is cat ID 6.
    I create a template called category-6.php, then create a new sidebar called 'web-development', inside that sidebar I put a popular posts widget set to retrieve the top stories from cat-ID 6. Then I'm getting the popular stories from that category whilst on that category page, but I've had to create a whole new template and sidebar to do so.

    Is there a simpler way for me to automatically get the popular posts on a per-category basic?

  13. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    Ah, I see. Don't worry, creating new templates won't be necessary.

    A more detailed explanation:

    As you probably know, when a user visits the category archive WordPress loads category.php (or category-ID.php, if found). In any case, the category ID can be retrieved then - WPP can list the most viewed/commented posts under X category.

    So, you don't really need to create a new template for each category unless you want it to behave on a different way (eg. always show up to 5 posts everywhere but on Category X, where you want to show 10 posts). If that's not the case and you always want to show the top 5 posts, then you're OK with just category.php. No need to create another template for that. WPP will know that when viewing the category archive the expected behavior will be "list the top X posts on this category ordered by Y".

    Hope that clarifies things a bit :)

  14. andy999
    Member
    Posted 8 months ago #

    So there's currently no way to show top posts of each category on the category pages without creating new templates for each category that you want to do it on?

  15. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    It can be done, only not with the widget version of the plugin. Here's how I would do it:

    In your category.php file, put this somewhere:

    <?php
    
    if ( function_exists('wpp_get_mostpopular') ) {
    
    	// We're viewing the category archive, get top posts under this category
    	if ( is_category() ) {
    
    		$catID = get_query_var('cat');
    		wpp_get_mostpopular( "range=all&stats_views=1&order_by=views&cat=" . $catID );
    
    	}
    	// We're viewing some other page, don't use the category filter
    	else {
    		wpp_get_mostpopular( "range=all&stats_views=1&order_by=views" );
    	}
    
    }
    
    ?>

    As I said before, this feature will be integrated into the plugin and a simple switch on/off will enable/disable it.

  16. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    Actually, that code I posted before works everywhere, not only on category.php. Here's a simplified version that will work only on category.php:

    <?php
    
    if ( function_exists('wpp_get_mostpopular') ) {
    	$catID = get_query_var('cat');
    	wpp_get_mostpopular( "range=all&stats_views=1&order_by=views&cat=" . $catID );
    }
    
    ?>
  17. andy999
    Member
    Posted 8 months ago #

    Ah, that's excellent! How would I go about getting the featured image/author name etc? Or just generally having my own markup for the output?

  18. andy999
    Member
    Posted 8 months ago #

    I took a look WPP files and was able to generate date, author etc with shortcodes, but I can't figure out how to get the featured image!

    EDIT:- Never mind, this is how I done it.

    WPP is seriously the best plugin.

    <?php
    
    				if ( function_exists('wpp_get_mostpopular') ) {
    					$catID = get_query_var('cat');
    					wpp_get_mostpopular( "range=weekly&stats_views=0&stats_comments=0&stats_date=1&thumbnail_width=300&thumbnail_height=190&order_by=views&cat=" . $catID );
    
    				}
    
    				?>
  19. Héctor Cabrera
    Member
    Plugin Author

    Posted 8 months ago #

    For the thumbnail, you need to pass the thumbnail_width and thumbnail_height parameters to the function.

    For using your own markup, use the post_html parameter (eg. post_html='<li>{title} <span class=\"post-stats\">{stats}</span></li>'). There's a complete list of what I call Content Tags (see {title} and {stats}?) in Settings > WordPress Popular Posts > FAQ at the end of the page.

    Edit: I'm glad to know you find my plugin useful!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.