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

74 thoughts on “Category Posts Widget 2.0

  1. 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

  2. After activation of version 2.1 I have error in wp_inclufrtd/query in line 610. Can You know what it can be?

  3. 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 ;-)

  4. 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

  5. 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.

  6. 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?

  7. 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.

  8. 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

  9. 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.

  10. 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

  11. 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.

  12. 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

  13. 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.

  14. 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;

  15. 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 :)

  16. 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?

  17. Thanks for the fix, but it can’t solve my problem.. The post still appear in every page.

  18. 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.

  19. 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?

  20. 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.

  21. 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.

  22. 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

  23. Pingback: Zabra Boof » Blog Archive » New Look

  24. Im looking for something similar to this widget, category post in drop down list form is it posible?

  25. 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)?

  26. 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?

  27. 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

  28. 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?

  29. 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

  30. 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.

  31. 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

  32. 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!

  33. 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!

  34. 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

  35. 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

  36. 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

  37. 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!

  38. 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?

  39. 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.