Category Posts Widget 2.0

Update: Category Posts Widget has been updated to version 3.0!

I just released a long overdue update to Category Posts Widget. At the time of this writing, it has been downloaded over 23,500 times and has an average of 4.5 stars from 22 people!

CPW Stats

CPW 2.0 has been included with Press75 themes for sometime now. I haven’t heard any problems with it yet so it should be pretty stable. I updated it to use the new widget API so it is only compatible with WordPress 2.8 and above. It also supports a little plugin I wrote called Simple Post Thumbnails.

Download

This was posted on July 29, 2009. It’s a prose on cpw, plugin, and wordpress. CommentsHope you like it.

  • Joe Chin
    Thanks for this great plugin. It could be a bug? When i activate this plugin, there is a post (from category defined in widget) that appear in every pages. Can you help me? Thanks
  • Joe Chin, I just released a small update (2.1) that should fix this.
  • buruszur
    After activation of version 2.1 I have error in wp_inclufrtd/query in line 610. Can You know what it can be?
  • wescht
    hi,
    i got an error:
    Fatal error: Call to a member function have_posts() on a non-object in ---snip---/wp-includes/query.php on line 610

    i fixed it by moving "global $wp_query" just before "$old_query = $wp_query;"

    btw, thx for the plugin ;-)
  • Hi wescht, thanks for the fix. I've updated the plugin (again). Now version 2.2.
  • GarajimdakiEjderha
    Hello,

    I was using 2.1 troubleness but when i updated plugin, I have a trouble.

    What is the problem? For example, for media category. If a compose the category posts for Media category, hence my blog title is Media | Blog Name. I can not fix this. I wish, I did not update. Can you give the download link for category posts 2.1?

    You can see the problem @ http://garajimdakiejderha.com
  • GarajimdakiEjderha
    Ah, I downloaded 2.1 from wordpress.org

    Thanks.
  • GarajimdakiEjderha
    Oh, I downloaded 2.1 but I still have problems and this time I really did not understand why the problems are continuing. This time, plugin changes title structure.

    For ex. Postname is ABC and Blog Name is BLOG

    The title must be Postname | BLOG

    But after install 2.1 title is this: Postname – BLOG

    Before, I was using 2.1, this was not actualized. I don't want this. I was using plugin troubleness but when I update, pof. It is very bad.
  • This plugin does not affect the title in any way. A different plugin is probably causing the problems.
  • GarajimdakiEjderha
    I am very happy with version 1.3.3 :)

    Thank you for everything.
  • i use the pagebar plugin on my site, since upgrading category posts plugin the pages: 1,2,3,4 etc.. now shows underneith category posts also.

    it didnt before and i havnt updated pagebar. any ideas?
  • Bleh
    Still not working! I activated 2.2 and my main page displayed all the posts of one category. I deactivated the plugin and it went back to normal.
  • Hey James, thank you for your plugin, it works wonders. I modified your script in order to meet my site's needs; I included truncation support and preg_replace support for replacing strings in titles of posts, which I needed in particular for my site. If you would like me to publish this code or if you would ilke me to send you the code so you could include support for these options in future releases let me know.

    Thanks,
    Michael
  • Andrew, it looks like pagebar is injecting itself into the widget when it does the automatic insertion of the page bar. You should contact the author of pagebar for a fix.
  • Nick
    Its a great plugin James thanks. I have a conflict problem with "different posts per page". When category Posts is enabled all post links point to the last post- weird. I had to disable it for now. I need to revert back prior to 2.2
  • Color me stupid, but I'm not familiar with how to get multiple instances of the widget. I don't see a setting, but I must admit, I don't do widgets often so perhaps it's an issue with my theme or a setting elsewhere I'm missing.

    Many thanks in advance for any insight.
  • hi
    thank you about plugin
    but it has a problem
    if you have 3 column theme like i3theme
    and you put this widget in the left side that loads earlier than main col it affects post showing in main page
    i mean if i select cat no 1 for showing in widget, main page will also display that category post and if you put the widget in right side that loads after main page there is no problem
    i think this plugin rewrites main loop while ( have_posts() ) : the_post();
    sorry if my english isnt good
  • wescht
    hi,
    it seems that once again, the trick with saving $old_query doesn't work.
    i dumped $wp_query in my footer, and it seems like the query is the one performed by the plugin.
  • Thanks for the heads up wescht. I will look into it since it seems to a common issue.
  • wescht
    in short (my previous post has not arrived?)

    NO golbal $wp_query

    // Save old query...
    $query_backup = clone($GLOBALS['wp_query']);

    // Won't even know I was here...
    $GLOBALS['wp_query'] = $query_backup;
  • I got the error:

    Fatal error: Class 'WP_Widget' not found in D:\PHPnow\htdocs\wp\wp-content\plugins\category-posts\cat-posts.php on line 11

    any idea?
  • Hi, i ve been using your plugin to a friend site that i maintain. I recently upgraded to WP 8.2 along with an upgrade to your plugin. Then it just show every post of the category i wanted in ALL pages.

    I did the fix that wescht suggested above and i confirm that it works!

    Thx for your plugin :)
  • Yuna
    Hi James, I really like this plugin and it's mostly what I need. I've been wondering though if you could add the option of having the post list as a drop-down menu?
  • Joe Chin
    Thanks for the fix, but it can't solve my problem.. The post still appear in every page.
  • Okay guys, thanks for bearing with me. I think I've finally fixed the whole $wp_query globals issue. Version 2.3 instantiates its own WP_Query object so that the $wp_query global is untouched and thus shouldn't effect anything else.
  • Kev
    I've loved this plugin for ages now, but I'm having a niggling problem when I upgrade sites from v1. All the previously setup widgets disappear and I have to set them up again after the upgrade. It looks like existing installed widgets are not remembered during the upgrade process. Anyone else having this issue?
  • Hi Kev. This is normal and I probably should have included a warning. I rewrote the widget to use the new widget API introduced in WP 2.8 but as a result the old options are lost.
  • Zoe
    A warning would have been nice! Not that it's hard to fix, but my boss was very concerned given recent hacks and etc, etc.

    It's a great plugin, thanks.
  • hello,

    this is a great plugin, but why you don't implement thumbnails in the code? take a look on right side og gourmandine.ro
  • mak sev
    Im looking for something similar to this widget, category post in drop down list form is it posible?
  • Elizar
    Question... this plugin lists the posts in order of when they were created (newest on top, oldest on bottom). How do you make it list posts in alphabetical order of the post's title (A to Z)?
  • Elizar
    Hmmm... still trying to figure out how to alphabetize post entries with this plugin. The WP site says I'm supposed to use "'&orderby=title&order=asc&posts_per_page=-1'" before something called the loop.

    I think it's this in the plugin right:

    "while ( $cat_posts->have_posts() ) : $cat_posts->the_post();"

    So how do I shove that in there?
  • hello i use this plugin with wordpress 2.8.3 but widget doesnt show category posts in widget at main page
    but in single posts widget work very well
    please help me
  • Audiostein
    Hello James,
    first of all thank you for this great widget.

    Is there a way to get the widget, when on a single post, to list articles from that posts categories?
  • Hi James
    I am using WP 2.8.1
    When I try to activate your plugin I Get
    "Plugin could not be activated because it triggered a fatal error
    Fatal error: Class 'WP_Widget' not found in /home/content/t/h/a/thaichimes/html/wp-content/plugins/category-posts/cat-posts.php on line 11

    Any ideas please
  • Fer
    Plugin working great for me.
    I think it would be very interesting to be able to scroll up and down when there are more than x posts in it and if it were like a carrousel that would be great.

    Do you think this could be possible?.

    Thanks.
  • Lock
    When used with thumbnails, everything messes up.

    Is it necessary certain thumb size?
  • Bryan
    Can anyone help me with styling this plugin?

    1. Can I somehow make thumbnails to show on the top of the post titles?

    2. How do I make the post title list to display horizontally and not vertically?

    example:

    Category Title
    thumbnail thumbnail thumbnail
    Post title 1 Post title 2 Post title 3
  • JC
    Hey James -- Love this plugin and especially of the customized features included. I chose it because of the thumbnail option in particular -- awesome!

    One thing though -- while the functionality seems to be working well, the styling I'm getting is pretty buggered (I'm using it in the Thesis Theme). I haven't been able to get borders to show around thumbs, for example; Also the title and excerpt text tends to come out flush against the thumb which makes it look pretty ugly.

    I guess my question is -- how should I alter this in order to get a consistent styling? Do I just go into the plugin and edit it there? (I'm a fairly novice coder, so I'm a little reluctant to mess it all up).

    Thanks!
  • JC
    Hi James -- One more thing I found. For some reason when I add new categories through the dashboard, the category post widget only wants to recognize the same existing four that I have. I don't think it's picking up any new ones. Any way to fix this?

    Thanks!
  • Hello,

    I'm using this plugin in my sidebar on my homepage, but for some reason it is also showing up on my static pages. This wouldn't be so bad, but it isn't only presenting the excerpt of the post. Here's links to my homepage and a static page...

    http://www.aaronhenderson.com/
    http://www.aaronhenderson.com/contact/

    Any help would be greatly appreciated, this plugin is exactly what I wanted...
  • vb
    Great plugin, thanks. How could I get the more tag to work with this plugin? Thanks again.
  • Jim R.
    JC - When you add a new category, it is initially empty. The widget only displays categories that have at least one post in it. To fix this, edit the widget by replacing the line that begins:



    with

    0, 'name' =>

    You need to add the 'hide_empty' => 0, into the array
  • Hello,
    I think this widget is just what I need, but something is wierd when it is added to my page...all of the text is white, etc...only when I hover over can I see what is going on. Which styles does this widget use?
    Look at the bottom of the page:
    http://www.livearchitecture.net
    Best, Luis
  • Peter
    Hi James -- I upgraded to 2.3 for 1.3 and it made some other plugins misbehave. The reason is that in this line:

    while ( $cat_posts->have_posts() ) : $cat_posts->the_post();

    you change the global $post variable that will cause some problems for plugins executing after yours. The old code did not do this.

    Reverting to the 1.3 resolved my issue.

    Cheers,
    Peter
  • Conrad
    It's great. you're perfect. now change.

    This plug in is terrific. But here's my issue: with WP 2.8.4, and CPW 2.3, I set the widget to display the 5 most recent posts in a category. On the main sidebar, this works flawlessly, but on all other post or page sidebars every single post in that category is listed. My theme is Tarski 2.4, if that affects anything...

    And THANKS!
  • teliot
    I have also problem with cpw 3.3. when i want to display the 3 most recent posts in a category, but this doesn't work on the main saidbar. it's work only in the category-sites, single pages...

    what should i do?
  • I'm having the same issue as conrad, WP2.8.4, CPW 2.3, unstandard 1.2.1... any help would be much appreciated!
  • Tom Callahan
    Hey, thought I'd share a change I made to 2.3 -- added the ability to auto-select the category of whatever category the post is in. So I added an "Automatic category selection" checkbox to the admin -- when checked, that disables the category dropdown and the widget gets the category of the post as the category for the menu. Everything else is the same.

    All of these changes go in cat-posts.php.

    In function "widget" add this after "extract($args);"
    =====

    //automatic category selection
    if ($instance["auto_cat"]) {
    $instance["cat"]=get_cat_ID(single_cat_title('',false));
    }

    =====
    In function "update", add this before "return $newinstance;":
    =====

    $new_instance["auto_cat"] = (bool) $new_instance["auto_cat"];

    =====
    Then add this in before the containing the Category dropdown:
    =====


    <label for="get_field_id("auto_cat"); ?>">
    <input type="checkbox" class="checkbox" id="get_field_id("auto_cat"); ?>" name="get_field_name("auto_cat"); ?>" onclick="document.getElementById('id_base . '[' . $this->number . '][cat]'; ?>').disabled=(this.checked)?true:false;" />




    =====
    And finally replace the dropdown itself which is originally this:
    =====

    $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>

    =====
    with this:
    =====

    $this->get_field_name("cat"), 'selected' => $instance["cat"], 'disabled' => 'true' ) );
    } else {
    wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) );
    }
    ?>

    =====

    The only thing I can't get working is that when you save the widget options, the dropdown is enabled no matter what the automatic setting is -- but that's minor and mostly cosmetic. The PHP is all correct as far as I can see so I assume it's something related to WP -- I'm not a WP expert by any means.

    If you want the full source let me know and I'll send the updated code.
  • Tom Callahan
    Sorry about the first version of this post, the comments stripped out some of the code. Here it is linked:

    www.thomascallahan.org/posting/wp-cat-widget-mo...

    That's a modified version of "cat-posts.php" in the plugin.
  • Brian Dowd
    Hi James,

    This plugin is just what I needed, thank you and well done!
  • Birkoff
    Feature Request, can you limit the length of the posts without using the excerpt or more tag.

    Cheers,
    Birkoff
  • Hello,
    I've uploaded the plugin & activated it, then dragged it into sidebar1 in the widget area, but nothing shows up on my site - what code needs to be in the sidebar to make it appear please?

    Thanks,
    Dave
  • Hello there,

    I changed a really small portion of your script to be able to manage the OFFSET of the posts. This way if you want multiple posts but different from same category you need the offset thingy.

    This is what i have changed:

    Modified:

    $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);

    to

    $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&offset=" . $instance["offset"]);

    //for the query

    and added


    <label for="get_field_id("offset"); ?>">
    :
    <input style="text-align: center;" id="get_field_id("offset"); ?>" name="get_field_name("offset"); ?>" type="text" value="" size='3' />



    right after



    <label for="get_field_id("num"); ?>">
    :
    <input style="text-align: center;" id="get_field_id("num"); ?>" name="get_field_name("num"); ?>" type="text" value="" size='3' />





    This way i added the offset thingy in the form in widgets.


    Thanks for the great plugin!
  • discostrings
    Thanks James--this is a very useful widget.

    I ran into one problem: when using it on single pages, I have other widgets below it that display content like the_author() from the post on the page. Category Posts never resets the loop it creates back to the main loop, so when the_author() is called in a subsequent widget, it retrieves the author of the last post from Category Posts.

    The fix is easy: I just called wp_reset_query() somewhere between lines 62 and 67 and everything worked as expected. It just took me a long while to figure out because I thought it was a problem with my own widget below!
  • Sheena
    How do I include this on my blog manually if I don't want to use widgets?
  • Hi James, thanks for this great plugin. I just have a question. Is there a php snippet I can use to call this function from within a template file instead of using widgets in WP-admin?

    Again, thank you for this super plugin! I was really happy to find it after days of Googling. :)

    P
  • This is a great plug-in, just got one little thing....

    When I turn on excerpts, they are heavily indented. How can I fix this? Is i t my CSS that is doing this?

    Here is an example:

    http://csbconline.net/wp-content/uploads/2009/1...

    Thanks for making this great plug-in!
  • Hi,

    Im currently redesign my blog with your category-post plugin within it. It was really helpful! Thank you very much James.

    But, is there any way so the plugin can display random post from the selected category?
    Thanks before.
  • Mark
    Thank you for this plugin. In a previous version of the plugin I believe the class for the active link would change however this has disappeared on upgrade. Any plans to restore this feature?
  • Thanks for the awesome plugin! It's so great actually, that I want to use it for my all my recent posts.. as I have yet to find one that uses the custom excerpt AND lets you pick the thumbnail to use (via simple post plugins). If i created a separate instance of the plugin, how hard would it be to tell it to pull posts from all categories versus just the one?

    and for those who want to use this w/o a widget aread check out "amr shortcode any widget". it lets you call any widget from [do_widget "widget title"]. found that today and it works a treat.
  • Fabio Sarmento
    Sup bro! really nice plugin! congrats!

    But i'm really curios how i can handle the script manually? i dont use widgets in my template!

    Thanks in advance
    -Cheers
  • Great plugin. I might improve it to provide also the number of comments. I will notify you if i do :)
  • game
    Thanks for plugin. It very nice.I will try.
  • Hi, this is a really simple and cool plugin and is just what I need.
    Only thing is that it seems only to show one image for all the diferent categories.
    I use the widget 4 times in one place (to show 1 post from each of four categories) and it shows the same image that I uploaded in one category for each of the others.
    Any ideas on how to fix?

    Thanks again.
  • Yeah, I'd really like to use this for a WP site's sidebar, but I don't want the widget as it's currently done (because too much WP's CSS is now dedicated to other areas of the site that look wrong when I just drop the widget in as-is). I have my own unique-styled div all ready to house it. What is the PHP code I can just drop into the sidebar.php page inside the to call up the function? I just want the top 3 headlines to display in my div from the "Blog" category. Thanks.
  • Would like to have the posts listed alphabetically rather than having the most recent at the top. Any way to configure for this display order?

    Great plugin otherwise! (Almost) exactly what I needed!
  • mike
    Thanks, great plugin. I need to make one slight amendment to it. I want to create a tabbed sidebar with three categories. I want to be able to only show posts for the selected category in the side bar when you click on the current tab.
    By default the widget allows you to choose a default category to show but you cannot change the list of posts that appear in the sidebar. I want it to change the list of posts when you select a different category tab in the sidebar. Hope this makes sense.
  • Hi

    Thanks for this plugin. It's exactly what I was looking for.

    However, is it possible to display the posts in REVERSE chronological order starting with the oldest ? I would really LOVE that feature

    In fact, it's available in another similar plugin. The only problem with that plugin is it only allows 1 widget whereas yours seems to be unlimited
  • Hi James - Thanks for the plugin. I came across a situation I needed but it doesn't cover, so I will give you the fix.

    I have a category archive page, using wp-pagenavi to o handle paging.

    My theme is based on the carrington-blog theme, at least the part which handles the archives page.

    I also have your widget on that page, displaying items in the same category.

    For reasons I haven't been able to figure out, your plugin uses the value of "posts per page" set in the theme settings admin page. I would like your plugin to use its own setting of course for the number of posts to display.

    This may be due to a filter or something I am not aware of, but I have a work around for you.

    First, set the query in your plugin to have nopaging=1:

    // Get array of post info.

    $cat_posts = new WP_Query("posts_per_page=" . $instance["num"] . "&cat=" . $instance["cat"]. "&nopaging=1");


    This will actually ignore the number of posts, but the next piece of code fixes that.

    We change the loop structure in the plugin to:

    $post_count = 0;

    while ( $post_count the_post();


    ....

    $post_count++;

    endwhile;


    That's it!

    Even without my theme/plugin combo, it should still work as before. But with the combo, it still works!

    So please consider adding this to the next version, users of complex magazine style themes will thank you! :)
  • oops, that while statement is:

    while ( $post_count < $instance["num"]) : $cat_posts->the_post();

    Sorry ...
  • I changed this line:

    $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);

    to this:
    $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&orderby=id&order=asc");

    And that gave me order using ids in ascending..Just in case someone was seeking for the answer :)
blog comments powered by Disqus

back to the top