WordPress Category Posts Plugin v1.0

by Brian Groce on May 27, 2005

I needed to create a nice, simple list of all posts in a single category and couldn’t find any WordPress plugins to do what I needed, so I created the WordPress Category Posts v1.0 Plugin.

Check it out and if you see anything that looks like a bug, have any questions or the documentation needs corrected, please let me know.

[Note: This has been updated.]

About The Author: Brian Groce

Brian Groce is a native Indianapolis resident and is the President & CEO of Watershed Studio, a web design & social media marketing firm located in the historic Stutz building in downtown Indianapolis. Brian is also a co-founder of Indy Media School and the man behind the curtain of all things Surge Bucket Media related. But first and foremost, Brian is the husband of his beautiful wife Amanda and the father of a house full of little ones.

{ 40 comments }

Paul Phillabaum June 8, 2005 at 11:14 pm

woohoo. I don’t have to figure this out from scratch! Thank you!

So, an additional parameter I’d like to see is number of posts to display. I’d like to see the X most recent posts w/ a given catID. I suspect this is trivial, but I haven’t figured out how to do it yet, so I thought I’d make the suggestion.

Paul Phillabaum June 8, 2005 at 11:31 pm

double woohoo.. A quick look at the database description for wp and…

I modified the ORDER statement to read

$get_posts_in_cat .= “ORDER BY $wpdb->posts.post_date DESC “;

and added this after the order statement.

$get_posts_in_cat .= “LIMIT 10″;

pamG August 2, 2005 at 4:20 pm

Does anyone know how to tweak this so that the posting date appears with the link? I’ve tried, but I suspect my ignorance of the “echo” command is ultimately causing all the errors, after I add varous combos, trying to get to the desired goal. Thanks!

apek September 4, 2005 at 8:44 am

how to use this script??
where to put it?
the readme is not clear..i’m a newbie in wordpress…
please explain step by step example how to use this…

anna November 30, 2005 at 5:40 pm

great little plugin – i’ve been trying to wrap my brain around this all day – i needed to display 5 posts + short extract from one category arranged by date on the front page. Got stuck on this point so thanks LOTS!

wonder if anyone else needs the extension, then i’ll put up the code.

FElipe December 10, 2005 at 9:07 pm

I need to show the excerpt of the post, but I don’t know how! Could anybody help me?

Brian Groce December 11, 2005 at 2:06 am

Add this to your select…

$wpdb->posts.post_excerpt ,

Add this to your loop…

$post_excerpt = $posts_in_cat_row['post_excerpt'];

And echo $post_excerpt where desired.

Michael December 13, 2005 at 1:03 pm

I am totally blown away by your WP Category Posts plug in and the level of support you provide. It’s fantastic and thank you for making such an easy to use feature.

I was wondering if you could tell me how to rescrict the number of posts being displayed.

Thanks again for your help and keep up the good work.

Michael December 13, 2005 at 9:07 pm

Oops I forgot to mention that it is the first number of entires I need. Many thanks for your help.

Michael December 15, 2005 at 8:09 am

$get_posts_in_cat .= “LIMIT 10″; works perfect for limiting, but I have no way of making the most recent posts display.

$get_posts_in_cat .= “ORDER BY $wpdb->posts.post_date DESC “; generates errors.

Mohib December 28, 2005 at 2:38 am

Hi,

This is really a useful plugin. I was surprised not to find it in the core WP code.

I was wondering if it is possible to show only specific posts from a specific category?

Thanks a lot,
Mohib

Henrik December 31, 2005 at 5:53 am

This is a great plugin – should definately be included in the standard Wordpress distribution !

I have one small problem though, which only appears when WP Cat Posts is generating the displayed page… so i though the error might lie with the plugin:

Please have a look at http://www.aficionado.dk/
Place mouse cursor over the ‘cigarer’ category. – The ‘on-mouse-over’ displays the text ‘Anmeldelser af cigarer’ – this is ok!

But try to enter the ‘cigarer’ category .. now the ‘on-mouse-over’ suddenly displays Anmeldelser af cigarer – which looks silly.

Please forgive me for being a complete newbie when it comes to messing around in php codes, i’ve learned a little, but unfortunately not enough to solve this – i hope you can help me.

Perywinkle January 15, 2006 at 8:05 pm

Did any one notice that the 1st post in the category is skipped?

Also I am wondering how to wrap this in a ul / li

Paul January 20, 2006 at 2:36 pm

Great plugin, I agree with some of the other comments, this functionality should be in WP core. I have a few suggestions that might make it better.
Option to sort links by date, title, etc
Option to limit number of posts
Option to display category title as a link

If anyone knows how to do these, please let me know. I am not doing very good at learning PHP.

Jaron February 26, 2006 at 2:20 am

I’d like to know how you can wrap the result in a too if anyone can give me a hint… by the way, this is a very handy little plugin.

Jormungand March 22, 2006 at 12:15 am

Yes, how do you space out each link, as with and ?
And what did the poster Michael mean when this won’t display recent posts? It doesn’t?

emily March 22, 2006 at 11:38 am

if you edit the .php file at the echo command, stick a <li> at the beginning of the string and a </li> at the end of the string, both just within the single quotes. then, edit the sidebar in the theme editor, putting the <ul> tags around the <?php wp_cat_posts(3); ?>

Keith June 3, 2006 at 9:58 am

Hi! Will you plug-in enable me to list the posts under the categories in the sidebar?

Thanks,
keith

Richard July 15, 2006 at 2:05 pm

Many thanks for this plugin – it’s sorted out an issue that has been driving me nuts. All the other solutions I’ve tried have fallen over when a post is in more than one category.

I found that $cat always gave me the correct ID for which ever category page I was on. So I added it to in place of the static number (3).

Hey presto – I put the above code in sidebar.php and it works like a dream. I get the (correct) list of posts for whichever category page I’m in and it’s 100% automatic.

Very cool – Big Thks!

baba007 July 16, 2006 at 7:33 am

I added the select, the loop and the echo $post_excerpt … not working … i am using wordpress 2.0 … and it looks like this …
echo ‘‘ . $post_title . ‘‘;
echo $post_excerpt;

whot did i do wrong ? … PS … I suck at PHP … please advise

kris August 2, 2006 at 6:01 pm

Hi,

How do I include the date below the title?

gérald Morales August 6, 2006 at 7:22 am

Hi,
The plugin looks fine, but I can’t find any information on how to use it… pleeease heeelppp. What I need is to have the title of the category above the list of related posts. Is it the proper plugin to do that ?
Thank you,
Gerald

Matt August 21, 2006 at 3:34 am

Hi Brian,

Great plugin by the way – very useful indeed. Quick request though – can you think of a way of assigning a class or an ID to the current post in the list? I would like to highlight this if possible so if your plugin can handle this that would be great.

Cheers
Matt

Narada August 28, 2006 at 8:58 pm

Hi. I found this plugin in the comments of an OnLamp article. However, out of the box, it didn’t do what I needed for my project. Therefore I wrote my own Posts for Category plugin. I hope it proves useful to others just as it did to me. Your work in this plugin no doubt helped me so thanks.

caughlan December 30, 2006 at 2:06 am

I wanted to show a list of the posts from the same categoy of the post the user is reading. Sounds simple – but after a day of following all of the ridiculous advice from the wordpress forums (none of which mentioned this plug-in that I came across!), I stumbled across this and VOILA! It is perfect for my needs – once I put the $cat as the variable. Thank you!!

wanda January 31, 2007 at 3:54 pm

please, can you tell me how to use this plugin with “my post icons” plugin ?

jayne d'Arcy February 5, 2007 at 6:17 pm

Thank you for this plugin, which seems to be working fine in 2.1. My only request would be to be able to add the date a post was posted. How would this be done?

Jennifer February 11, 2007 at 12:44 am

I just tried the excerpt coding you have written here Brian and it will not show the excerpt in the brand new wordpress version. Do you know if its compatible or not? Here is the code I used:

posts.ID, $wpdb->posts.post_title, $wpdb->posts.post_excerpt ,”;
$get_posts_in_cat .= “$wpdb->post2cat.post_id, $wpdb->post2cat.category_id “;
$get_posts_in_cat .= “FROM $wpdb->posts, $wpdb->post2cat “;
$get_posts_in_cat .= “WHERE $wpdb->posts.ID = $wpdb->post2cat.post_ID “;
$get_posts_in_cat .= “AND $wpdb->post2cat.category_id = ‘$catID’ “;
$get_posts_in_cat .= “AND $wpdb->posts.post_status = ‘publish’ “;
$get_posts_in_cat .= “ORDER BY $wpdb->posts.post_title “;

$get_posts_in_cat_result = mysql_query($get_posts_in_cat);

while ($posts_in_cat_row = mysql_fetch_assoc($get_posts_in_cat_result)) {
$post_title = $posts_in_cat_row['post_title'];
$postID = $posts_in_cat_row['ID'];
$post_excerpt = $posts_in_cat_row[’post_excerpt’];

echo ‘‘ . $post_title . ‘‘; echo ‘echo $post_excerpt’;
}
}

?>

Thanks in advance for your help.

Juli March 24, 2007 at 12:43 pm

Michael, you’ve probably already figured this out by now, but anyone else: the quote mark after DESC is backwards.

Copy/paste this:

$get_posts_in_cat .= “ORDER BY $wpdb->posts.post_date DESC “;

Plugin is great!

seth April 5, 2007 at 1:03 am

Can anyone help me order the posts by date? I need Newbie directions.

Richard Brown April 13, 2007 at 7:36 am

Hi

I am using the plugin at:
Glass at Uzella Court Antiques.
As you can see I am using it to display a list of products. What would be great is whether it is possible to attach a thumbnail of the image against each link. Would this be possible please?

Thanks

Rich

SEO Best Practices April 16, 2007 at 11:30 pm

Hi, thanks for the information. I Uploaded “wp_category_posts.php” to my “wp-content/plugins” directory. Now I’m in the process of putting the line:

Forgive my ignorance, but I don’t know the proper syntax to replace the number (3) with the ID category I want to display, I called that category: most read.

Can anybody give me some light in that matter, thanks in advance.

littleoracle June 21, 2007 at 5:48 pm

i heart this plug-in. it was exactly what i needed!

thanks so much!

mgalib April 30, 2008 at 3:13 pm

I upgraded to WP 2.5 and it started giving me error…
================
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in wp/wp-content/plugins/wp_category_posts.php on line 25
===================

Is there a way around it ?

Thanks in advance !

Richard May 1, 2008 at 4:13 am

I’ve been using your plugin for a quite a while and am very happy with it.

Don’t know whether it’s a result of the recent Wordpress upgrades – my blogs are on ver 2.51 – but an error is now displayed:

‘Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in …\wp_category_posts.php on line 25′

The line in question reads:
while ($posts_in_cat_row = mysql_fetch_assoc($get_posts_in_cat_result)) {

Paolo May 13, 2008 at 12:31 pm

Thanks for your plug-in!!
Is possible that the list of post automatically update when I add a new post.
Mybe the plug-in have a limit of post to show?
Many thanks in advanced

CJ June 5, 2008 at 11:09 am

Could you update this plugin to work with Wordpress 2.5.1? The database format has changed, and so this plugin no longer works with the new version.

cheerful July 30, 2008 at 6:23 pm

at wp 2.6

‘Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in …\wp_category_posts.php on line 25′

:( ???

Steve August 8, 2008 at 7:33 pm

Hi,

The plugin doesnt work with wordpress 2.6….will this be updated or is there another plugin like this that we can use ?

Thanks
Steve

Marty August 18, 2008 at 2:40 am

Hi, like others, I would like this plugin working in 2.6. Or is there any other solution?

Previous post:

Next post: