Category Posts Widget 1.3

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

As promised, I’ve updated Category Posts Widget. Version 1.3 brings one new feature to the table: an option to show a post excerpt. I also converted the widget to the new WordPress 2.5 system of adding multiple widgets so 1.3 will only work on WordPress 2.5 or later. Please donate if you like this plugin! Full list of changes below.

Changes:

  • New option to display post excerpt below permalink.
  • Display as many posts from a category as you want.
  • Add as many widgets as you want.
  • WordPress 2.5 or later compatible only.

Note: You may have to reconfigure your CPW widgets if you are upgrading from a previous version.

Download

You can download Category Posts Widget 1.3 at the official WordPress plugin repository.

Donate

This plugin was created by me and is made available free of charge. However, if you would like to show your appreciation, you can donate via PayPal by clicking the donate button in the sidebar. All funds go towards paying for my college expenses.

This entry was posted in Code and tagged , , , , . Bookmark the permalink.

92 Responses to Category Posts Widget 1.3

  1. Michael says:

    Nice work on the widget. But I have a question.

    I am wanting to use the function on the home page of my blog(within the post) and I can not figure out what to type in to specify a category.

    function c2c_get_recent_posts (
    $categories = ”,

    if I type in $categories = ’0′, I believe I get all posts, but I can’t figure out what the category ID’s are.

  2. max says:

    Very useful to us.
    I want to see sorting order on the posts. It’s latest first at the moment. I want alphabetical coz it’s used as a menu block.
    If I get someone to add it, will you include it into your code for others, please?

  3. Kjetil says:

    Hi
    Thanks again for a great plugin!
    I’ve had a weird experience, though: I’ve set up a widget for each of 26 categories (big site…) – but the contents/setup in each of them are often just deleted. The same happens with the settings I’ve inserted in the Widget Logic field (link below). Also, in those cases, the selected category is reset to the category with the lowest ID.
    I suspect there’s a plugin conflict, but I have not managed to find which is the sinner.
    Ideas?
    Thanks,
    Kjetil
    PS If you like, I can e-mail you a plugin list.
    http://wordpress.org/extend/plugins/widget-logic/

  4. Mike says:

    I am new to WordPress and not sure if this plug in will do what I need. Here is my blog, http://www.dietdrinkaddiction.com
    When you come to my site this is my home or static page I guess you all it, and on the left is a widget I acivated called Recent Posts. I want all my recent posts to show here, but not below the text in the static page. If you click on the recent post there, on the next page you will see my second post. Can this widget help me to show all recent posts on all pages, but just not add them to the text of the static home page?
    Thanks,Mike

  5. zhrance says:

    Hi there, I really like your plug-in! but is it possible to show images in the excerpt… The reason I ask is because I would like to use this plug-in to highlight some posts related to a specific category! Let me know!

    Kind regards,

    zhrance

  6. Ben Cheng says:

    Hi James! Great plugins! I’ve been using it but just come across a problem with solution, hope that can help some ppl:

    At line 58 of cat-posts.php, the call to “the_excerpt” depends on the global variable $post. But in the code the $post variable actually didn’t pass to global area so the wordpress’s function get_the_excerpt may not get the correct post excerpt…. a solution would be using $post->post_excerpt instead.

  7. James says:

    Ah, that must be why one user said the excerpt was the same on all his posts. The problem with $post->post_excerpt is that you have to specify an excerpt manually when writing a post.

    In theory the way I have it should work fine, I’ll have to look into what the problem is when I have time.

  8. Bill says:

    Love the plugin, but as with many of the widget type plugins that I find, you haven’t followed the standard (I’m assuming it’s the standard because it’s the way a plain text widget is output) for outputting the final code.

    Here is how the standard seems to work:

    AND here is how cat post does it:

    Your plugin should have a after the widget title and before beginning the list.

    I haven’t been able to get your plugin to work within my design so I’ve had to dig into your plugin.

    Otherwise the plugin is a life saver!

  9. farhang says:

    amazing plugin. looked for something like this for a long time

  10. Matt says:

    Great plugin. Do you have a version that can be embedded as a function in pages using the wordpress editor? Not yet confident making unique page templates and this would remove the need entirely!

    Cheers

  11. Chris Berry says:

    I’ve been looking for something like this for a long time to highlight some of my favorite all time posts. In theory it does exactly what I want, but when I test it, I don’t get an edit button on the widget to after the initial configuration. I’m on 2.5.1, and don’t have a huge number of other plug-ins in use.

  12. This is a great! I was looking everywhere for something along these lines.Is there a way to change how many words are in the excerpt? I googled this, but if I was to change the main excerpt setting it changes it for everything.If you have any advice it would very much appreciated.Thanks again for a great plug-in!

  13. Eugenio says:

    Hi James, is it possible to use this widget inside my template code? Im trying to do something just like this but to sort my posts by category. Basically displaying my category title, then some the posts, and the next category title and more posts. I know how to do this manually, but the problem is that when i add a new category, i would have to add a new loop too. Im looking for a method that will let me do this, and adds new categories automatically.

    Thanks!

  14. Pingback: thisisnotablog » Blog Archive » Work In Progress

  15. Indialogue says:

    Dear James,

    great plugin, spent hours looking for a plugin that would allow me to select posts from a particular category to highlight in a section of my blog I called the Forum. I wanted total control – being able to specify just one category which would be highlighted and listing all posts under that category. Your plugin saved the day!

    Is there a way I could now change the display from a static list to a cloud display of the posts? I just want to highlight them in some way, and I was wondering if you widget could be combined with a feature to turn them into a cloud. If you can let me know I’d be grateful. I would even try changing the php myself, though never tried that before. THANKS!

  16. Pingback: Category Posts Widget | What Simply Works!

  17. Mitch says:

    Hey James,

    Awesome widget, definitely one of the most handy around. One thing I would love though, is the ability to organise the posts alphabetically in the list. Is this possible? Even if you could just give me a hint as to how to do it myself that would be great.

    Cheers

  18. hi there, I just upgraded to wordpress 2.6 and it doesn’t work… Do you know what it could be?

  19. Adam says:

    I also just upgraded to wordpress 2.6 and the widget does not display on the homepage but does on other pages. Looks like there might be some incompatibility with Advanced Category Excluder too. It all worked with 2.51.

  20. Michael Shearer says:

    Hi James,

    Great plug-in. Can you tell me how to reverse the order so that the posts display oldest on top?

    Thanks!

  21. Michael Shearer says:

    I answered my own question:

    I added the following the the get_posts query string:

    ‘&orderby=title&order=asc’

    Kindly,

    Michael

  22. David Unrau says:

    Same dealio! Weirdest thing… it works on all the other pages on our site – even another page that has been edited to show posts from one of our main categories.

    This is the error output:

    WordPress database error: [Not unique table/alias: 'wp_term_relationships']
    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_cat_visibility ON (wp_term_taxonomy.term_id = wp_cat_visibility.cat_ID) WHERE 1=1 AND wp_term_taxonomy.taxonomy = ‘category’ AND wp_term_taxonomy.term_id IN (’1′) AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’) AND wp_term_taxonomy.taxonomy=’category’ AND (wp_cat_visibility.front=1 OR post_status=’static’ OR wp_cat_visibility.cat_ID IS NULL) GROUP BY wp_posts.ID wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 2

  23. Drew says:

    Great plugin!

    I have issues with it when using Advanced Category Excluder (I get different excepts than what the title is).

    If I can get it working with Advanced Category Excluder is there anyway I can get it to show the full content of the posts, rather than just the excepts?

    Thanks!

  24. KOK says:

    Hi!

    Thanks a lot for the plugin!

    I have another suggestion: I use your plugin to display a category which is *sometimes* empty, as I move posts from that category to anoter (archive) category.

    In that case, I’d like the plugin to not output anything at all (at the moment it displays the heading, but nothing beneath that).

    This is easily done by inserting the following line after “$cat_posts = get_posts(‘ …” (currently line 40):

    if (count($cat_posts) == 0) return;

    In order to be able to select empty categories in the widget control panel in the admin menu, you also need to append

    , ‘hide_empty’ => 0

    to the wp_dropdown_categories(…)-call.

    I’d be happy if you add this to the next version of the Plugin – thanks!

    Cheers, KOK :)

  25. Will says:

    For those who wanted the date, and a nicer format… change this:

    foreach($cat_posts as $post) {
    setup_postdata($post);
    echo 'ID . '">' . $post->post_title . '';
    if( $excerpt ) {
    echo '';
    the_excerpt();

    }

    to this:


    foreach($cat_posts as $post) {
    setup_postdata($post);
    echo 'ID . '">' . $post->post_title . '';
    echo '';
    the_time('F j, Y');
    echo '
    ';
    if( $excerpt ) {
    echo '';
    the_excerpt();
    echo '';
    }
    echo '';
    }

  26. Will says:

    except… er… that code didn’t work :|

  27. Gus says:

    Hi James,

    Great plugin! Would it be possible to display the number of comments there are for a post? I’d liket to display this comment count in the widget.

    thx
    Gus

  28. Gerald says:

    Hi,

    Thank you for this plunig. I am using WP 2.6.1 and I have a small problem with WP posts. In the widget details, I cannot select a category in the combo. Is-there something that I could do to amend this?

    Regards

  29. Davide says:

    Does anyone has ever tried to integrate the lang_switcher plug-in with category posts widget?

  30. Rowan says:

    Thanks for this – you’d think WordPress’s own widget could do this.

    I’ve modded it a bit to include a link to the rss feed of each category

  31. jacob says:

    Hi James, great plugin!

    Is it possible to use html code (i.e., ) in the title of this widget?

    Thanks!

  32. jacob says:

    Sorry, didn’t mean to bold my comment– was trying to use the “strong” tag as an example of the code I’d like to use in the widget title. Oops.

  33. WiZiE says:

    hi sir

    your plugin is great i`ve been looking this plugin for long time :)

    i`m glad i found this plugin

    i wana ask question how to add max letter for title

    i`ll be back for see your response

    regards :)

  34. Onur says:

    Thank you i use it. it’s perfect

  35. m+w says:

    Hi, a question about the widget:

    Is there a way to: 1/ show all categories, 2/ make the one with latest post to go first and 3/ show only one post from each category?

    Thanks :)

  36. Adam Finley says:

    Is there a way to change how many words are in the excerpt?

  37. Darren says:

    This widget is awesome! One Question…

    How do i update the code so the widget updates the code based on category you are viewing… So say it shows the last five posts from category 1 when you click on cat 1 and cat 2 when you click on cat 2 etc.

  38. Darren says:

    I have a good addition for you, if you want to set up so the “excerpt” displays as a hover over here is good code (note you do have to write exerpts for each post!

    ————– REPLACE ——————

    foreach($cat_posts as $post) {
    setup_postdata($post);
    echo ‘ID . ‘”>‘ . $post->post_title . ‘‘;
    if( $excerpt ) {
    echo ”;
    the_excerpt();
    }
    echo ”;
    }
    echo ”;
    echo $after_widget;
    }

    —————- WITH THIS —————–

    foreach($cat_posts as $post) {
    setup_postdata($post);
    echo ‘ID . ‘”>post_excerpt) {
    echo ‘title=”‘ . $post->post_excerpt . ‘”‘;
    }
    echo ‘>’ . $post->post_title . ‘
    ‘;
    echo ”;
    }
    echo ”;
    echo $after_widget;
    }

    —————— END ———————–

  39. Darren says:

    Ok for some reason the message board cuts off code, so the above code is wrong! Email me for code!

  40. Fragestunde says:

    Hi there,

    it’s a fantastic widget and works fine with my browser, but there is one problem:

    It is not shown with all the new browser versions like Firefox 3 and Internet Explorer 8. Look at my page, I included your widget in my sidebar on the right as the last point called “Stellenmarkt” (www.louis-e.de) . there should be two posts in it, but I don’t see anything with the new browsers (the old ones work fine). Anybody knows that problem??

    Thanks a lot for help

  41. Pete says:

    is there a plugin without the widget… I know I am still in dark ages but I just do not want to change my theme to support widget…

  42. David Couper says:

    Hi –
    Love the plugin. I want people to be able to click and read the full article from the excerpt, how can I do this?
    Thanks
    David

  43. Bill says:

    I would like to display category posts using this plugin at the bottom of pages I create, rather than a sidebar widget. Is there a plugin for that, or a shortcode solution? I am not real familiar with code to make my own changes yet, and I do not know how to convert a widget for that purpose. Any help would be great!.

  44. DoZ says:

    seems it doesn’t work well on new 2.7 …

  45. DoZ says:

    …or maybe I’m mistaking!
    :P
    ;)

  46. Gerald says:

    Hi there ! I am a fan of this plugin. However, there is something I would like to do and I can’t find an easy answer : how can I have a “current” style in order to highlight the post I am on ?
    Thank you.

  47. Marc says:

    Any chance of being able to pull a post randomly from a category?

  48. Marc says:

    If you can make this randomly pull from a category and display a single random post per day I can make a donation. Thanks!

  49. Alexander says:

    This is an excelente plug-in, I’m recently testing a new theme and I’m going to include this plug-in, however I was wondering if there was anywway to instead of giving it the category you want to list posts, there could be random category option.

    it would be easy to implement using the category IDs and the random php function:

    Replacing 9 for the lasyt category number. :D

  50. Christopher says:

    Hi.

    Wondering where I could find the CSS to change the output – mostly spacing of the text. I can’t locate the classes in the style sheet for the Theme (Wasteland) and I don’t see anything in the cat-posts.php file. I am missing something obvious (I hope so…)

    Thanks