Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.6   Updated Sunday, April 27th, 2008 at 8:20pm

Other Posts from Cat plugin for WordPress

This plugin will show the last X posts from the current category at the bottom of every post, or where you manually specify in each post. Using the built-in options page, you can choose the number of posts to show, set the header text, choose to show the post dates, select the format of the date, and choose whether or not to include the current post in the list. The latest version also has an option to show recent posts from all categories the current post is in.

Download

  • Latest Release (For WordPress 2.0 through 2.5)
  • International Version (For WordPress 2.0 through 2.2)

    One of our visitors sent in an internationalized version of this plugin, with full support for international text and date formatting! It includes English and Spanish support. This version is only supported by WordPress 2.0 through 2.2, and will not work in 2.3 or 2.5

Instructions

  • Download the above file, rename it from .txt to .php, and upload it to your plugins directory.
  • Enable the plugin.
  • Configure the plugin options (under DDOtherPostsFromCat).
  • Test it out by viewing a post.

Change Log

  • 04-27-08 Version 1.6 Added an option for excluded categories. Also a few other minor fixes.
  • 09-29-07 Version 1.5 Updated for WordPress 2.3. Added ‘Load Default Options’ button.
  • 06-11-07 Version 1.41 Added wrapper class around output (.ddop)
  • 05-16-07 Version 1.4 Updated for WordPress 2.2.
  • 01-28-07 Version 1.3 Fixed an issue in which a database error would occur when the plugin is set to check all categories that the post is in, and it is in only one.
  • 08-09-06 Version 1.2 Now if showing posts from all categories the current post is in, you can also choose to split them up into multiple lists (per category).
  • 08-08-06 Version 1.1 By request, the plugin now features an option to show recent posts from all categories the current post is in. It also has a CSS class added for easy changes.
  • 04-19-06 Version 1.0 First release. This is very similar to my ‘Posts by Author’ plugin but it lists other posts from the same category, instead of other posts by the current author.

Notice

Currently this plugin checks the first category a post is assigned to when generating a list of other posts in the same category. This means that it will work best for those of you who only assign one category to posts.

Styling

This plugin now has a div wrapped around the output with the ddop class assigned to it. For example, if you wanted to decrease the size of the text in the output, add this to your CSS file:

.ddop { font-size: 90%; }

Options

Here are the options available in this plugin’s options page in the WordPress admin panel.

Show at the bottom of every post

If enabled, this plugin will generate its data at the bottom of every post, before the comments section.

NOTICE: No matter what you have this set to, you can also manually call this plugin by entering the following line where you want the data to be shown in your post:

<!-- ddpostsfromcat -->

Check all categories that current post is in

With this option enabled, recent posts from all the categories (that the current post is in) will be shown. It will also show all of these categories in the heading (if you are showing one). Disabled, it will simply show other posts in the first category this post is found in.

Split categories into separate lists

This option only applies if the previous option (check all categories that current post is in) is set. It will allow you to split up the posts into multiple lists (per category) instead of all the posts being in a single list.

Number of posts to show from this category

This is the number of posts from the current category that will be shown.

Text to show before list

This is the header for the post list. If you want to use the category title in this text, use %C.

Show date after listed posts

This will show the post date after each post in the list.

Date format

If you are showing the date after posts, this will allow you to configure the date format (using the standard PHP date() format)

Include current post in list

This sets whether or not the post being viewed should show up in the list of other posts from this category.

Show newest posts first

If checked, this will show the newest posts first in the list. If not checked, it will show the oldest posts first.

Excluded Categories

This is a comma-separated list of category names you want excluded from this plugin. It is not case sensitive.

  1. thanks for a simple straight forward plug-in that saves me some work! One thing that I felt was missing was that, if the current post is included, it would help to have it marked. I’ve amended your plugin to add a class=”current-post” to the list tag.

    Another thing I didn’t see mentioned was that instead of having to use it in a post as a tag, it can be as well used in other places in the theme by calling [?php echo ddop_show_posts();?] directly. And it works, at least for me.

    Thanks again!

  2. i’m wondering if there is a way to display the 10 most recent posts of the same category at a custom place of the page, i’d like to insert it in another div but can find a way to do that…

  3. Version 1.6 Released

    This version has been verified to work with WordPress 2.5.

    An ‘Excluded Categories’ option has been added, as well as a few other minor fixes.

  4. 145
    drtopo

    Thanks for your great work.

    I have the same intention than Adil (#91): to exclude some categories (or to include just a few). I tried the solution proposed in #92, but nothing happens (it shows all the categories of the post).

    Any ideas? Thanks in advance.

  5. Is there any way to include a list of posts from a static page. This of course would mean the ability to also define which category to list…is this attainable using this plugin. I have been searching for a plugin to do this for a while, as I use static pages as part of a CMS solution with my websites.

  6. Hi, I found a problem and fix it.
    I had a post with “&” in it.
    So I’ve added htmlspecialchars to the output, like this htmlspecialchars($lpost->post_title), now the code is valid. :)

    Great plugin. Thanks !

  7. Hello,

    thank you for this great plugin! But I have problem it shows me:
    WordPress database error: [Table 'U7973116.wp_post2cat' doesn't exist]
    SELECT DISTINCT ID, post_title, post_date, post_category FROM wp_posts, wp_post2cat WHERE category_id = 48 AND wp_posts.ID = wp_post2cat.post_id AND ID != 14 AND post_status = ‘publish’ ORDER BY post_date DESC LIMIT 5

    You can check it at link above (my signature) at the end of the page.

    I am looking for reply.

    Thank you!!

  8. 141
    EssenzZo

    I uesd this plugin. Its working. But I need the php code to insert in my template. Please help me out.

  9. Hi

    It is a wonderful plugin. However, when I include more than one category, the posts seem to repeat. Is there a way to remove this duplication?

    Thanks
    Anand

  10. Just edit your plugin and take the text from the latest version and copy paste.

  11. 138
    LPX

    Hey man,

    Great plugin, but I get the following errors:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.' at line 7]
    SELECT DISTINCT ID, post_title, post_date, wp_terms.term_id as post_category FROM wp_posts, wp_terms, wp_term_relationships, wp_term_taxonomy WHERE wp_terms.term_id = AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.term_id = wp_terms.term_id AND ID != 500 AND post_status = ‘publish’ ORDER BY post_date DESC LIMIT 400

    Any idea what’s up?

  12. hey,
    thanks for the plugin. it’s great. honestly :)
    i’d like to know, though, how can i go about adding excerpts next to the listed titles. (i’ve seen two other users interested in doing the same thing. i would appreciate it if you could email me the solution as well or post it here. or even better, maybe adding it in a future version?)
    i would also be interested in knowing if there’s a way of listing related posts randomly.
    cheers!

  13. I searched the nine pages of comments, and didnt see a request, so I thought I would ask. Is there any way to include a list of posts from a static page. This of course would mean the ability to also define which category to list…is this attainable using this plugin. I have been searching for a plugin to do this for a while, as I use static pages as part of a CMS solution with my websites.

  14. This plugin is working PERFECTLY if I place the code in the post. Otherwise - the “automatic” trigger doesn’t seem to work.

    I could manage this way - but I’d love to have it work automatically l….

  15. Correction, I added “echo ddop_show_posts();” inside php tags to get the output on the sidebar.

  16. I added the following to my sidebar.php and it is working just nicely out of the loop:

    “ddop_show_posts();”

    These are of course contained with the standard php tag, which I can’t out into a comment.

  17. 132
    anomy

    Hi, I’m wondering if you have the php function to call it in the single.php template or any other templates?

  18. 131
    ovidiu

    sorry if this has been asked before, but I only read one page of the 9 comments pages :-(

    can I somehow use a tempalte tag to get the output? I would like this after my post rather than inside my post.

  19. Nevermind, just went through the plugin code and found you have to manually echo the output as the function doesn’t do it for you… should have put a bit of effort in before asking eh?

  20. Hi - thanks for the plugin, great idea. I’m having a problem with it at the moment though. It works fine until I try to output to the sidebar instead of underneath the post… just returns blank… any ideas?

  21. Hi, Dagon. It would be nice if you add the Drop-Down list (of all posts from current category) feature to this plugin (or the Drop-Down by Category plugin, which is very hard to incorporate into the template to display all posts from the current category when viewing a “single” post/entry).

    I hope you get what I’m saying and hopefully integrated the extra function to either of your plugins =P.

  22. Version 1.5 Released

    This version adds support for WordPress 2.3, and a ‘Load Default Options’ button has been added to the options page.

  23. Yes there will be. Keep in mind that WP 2.3 just came out, and I have updated several plugins, but there are many more to update, and a lot of things keep me busy these days :) It will be updated though soon, I promise.

  24. I have the same problem as aure. I installed wordpress 2.3 and its spits out errors on all my posts now. Will there be an update?

  25. Un saludo, tengo problemas con el plugin en wordpress 2.3, actualize mi wordpress y el plugin me arroja un error.

    A greeting, I have problems with plugin in wordpress 2.3, made an update in my wordpress and plugin throws an error to me.

  26. 123
    Олег

    Please, give me a file “dd-posts-from-cat.txt” v1.3 !!!
    I need it !

  27. 122
    nathan

    I noticed the AND post_type = ‘page’ had simply been removed in your latest update. I think it needs to be there, but NOT equals.

  28. 121
    nathan

    Ok, got back to this. The fix was as easy as changing the query (line 329) to post_type != ‘page’ instead of post_type = ‘page’. Evidently it was intentional to show other pages in case of there not being enough actual posts in the same category? Not sure, but this makes more sense to me. Thanks!

  29. 120
    nathan

    I’ve learned a little more about my situation (116). Wordpress has a bug(?) that applies the default category ID to Pages. Since you can’t even choose categories for Pages in the admin interface, this is, well, stoopid. So…I get a similar problem with any plugin that works with category ID’s.

    Matt, I’m guessing that adding something like if is_page() to change the cat ID to 0 for plugin purposes would work. With other plugins, I’ve just changed the post2cat db entries, but that’s a hassle. I thought Pages got a cat ID of ‘0′ previously…

  30. This is exactly the plugin I need for my site but like 115 and 117 it simply shows nothing at all. I manually inserted tags in posts and used the php code in the loop and still nothing.

  31. Two questions:

    Is it possible to avoid to show the “Other posts in same category” when there aren’t others?

    Is there a possibility to modify the SQL query to show random posts from the same categories?

    Many thanks in advance.

  32. Just tried the plugin but same as Christian 115 nothing happens, I tried with php code 113, still nothing, any idea (I’m on wordpress 2.2.1)

  33. 116
    nathan

    I’ve finally had the time to get back to looking at this (see comment 95). I downloaded the current file above and it’s still showing Pages as related posts to the default post category. Any help would be appreciated.

    Right now I just have the default category named “Don’t Use” for the benefit of the content writers, but one of these days they’ll mess up. :)

  34. 115
    Christian

    After installing and activating the plugin it seems to work, but I onl get the empty ddop div tag. Anyone ideas how to fix this and/or what the reason could be?

  35. Hi, I’m using the plugin and it works well.

    Anyway I would like to avoid to show the text “Other posts in same category” when there aren’t others; do you know how I can manage to do that?

  36. Dermod: Comments are displayed inside the loop, so yes, that is possible. You will just have to disable the option to automatically show the output on all posts, and instead, add this code to single.php, right after the call to the comments function:

    <?php echo ddop_show_posts(); ?>

  37. 112
    Dermod

    Great plugin, I love it, thanks. I see that it has to be run in the Loop - but is there a way of positioning it so that it displays after the comments?

    Thanks again

    Dermod

  38. Ronson: Unfortunately I do not have much experience working with other character sets, so I am not sure really.

  39. 110
    Ronson

    Hi, I installed your plugin on a test-run blog and I found a problem. My blog is in cyrillic. Every category, title and page name is in cyrillic and the problem is that the plugin shows my page title instead the post titles. It’s funny as it is supposed to show only posts from the same category. I don’t know from where it gets my pages :) Could you please confirm whether your plugin handles cyrillic posts.

  40. Fixed the problem the page called a plugin but just need a return on the page to work. Thanks and keep up the good work.

    Alex

  41. Hi
    I think your plug-in is really good however on a page I am getting this following error any ideas? Is there any way to exclude certain pages. I have tried the option of enabling the plug-in when you add the text string but this does not work. And the error is still the same
    The page is http://www.homelifeweekly.com/?page_id=5?total=9.98

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND homelife_posts.ID = homelife_post2cat.post_id AND ID !]
    SELECT DISTINCT ID, post_title, post_date, post_category FROM homelife_posts, homelife_post2cat WHERE category_id = AND homelife_posts.ID = homelife_post2cat.post_id AND ID != 5 AND post_status = ‘publish’ AND post_type = ‘post’ ORDER BY post_date DESC LIMIT 5

    Your help is much appreciated BTW I’m using Wordpress 2.2

    Thanks in advance
    Alex

  42. Further ideas:
    The plugin show ‘X posts from this category, or subcategory’? (If a post were in both a category and it’s subcategory, only the subcategory would be shown)

    There should be a possibility of putting the ‘number of posts found’ into the header (e.g. if the header is ‘X posts from (Category)’, but only X-1 posts are found, then X-1 should be used.

  43. Another nice plugin. Well done. One comment from me here, is that I would like the ability to not automatically add in the other categories, but to be able to choose where I want the list via a template tag.

  44. dhkeller: Just uploaded v1.41 which fixes this :)

  45. This is a fun plugin, which I really appreciate, but the styling you mention is not showing up in the version I have. I am running v1.4 of the plugin with WP 2.2, but the output does not seem to include “ddop” or an extra “div” anywhere ….

    Am I missing something?

  46. This is working wonderfully for new posts! It will make our site much more usable. But not for existing posts - so far, anyway, even if we open, edit, and repost. We’ll keep playing with it. (Running 2.1.2 - as per host - which changes WP versions slowly)

    So maybe will be able to solve problem on this end - but thought it worth adding to feedback.

    Thanks!

  47. Philipp: It should not be displaying anything if there are no other posts. I uploaded another change - try it out :)

  48. It works great now! Thanks!!! One suggestion: Maybe if there are no other posts in a certain category (new category) there shouldn’t be any mention of that category below the post as it will simply show up empty.

    Other than that it’s perfect. :-)

  49. Philipp: I just uploaded a small change - let me know if it helps.

  50. The plugin sounds great, and it works, however, I also get this nasty error message in the beginning of evry post:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mnt/ja2/02/722/00000013/htdocs/tlab/wp-content/plugins/dd-posts-from-cat.php on line 199

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mnt/ja2/02/722/00000013/htdocs/tlab/wp-content/plugins/dd-posts-from-cat.php on line 199

    So I had to disable it. Any advise?

  51. Subir: There is some code in the comments below.

  52. Right now the results will show at teh bottom of the post itself. But I would like to show the results in a sidebar. is there any way to do that?

  53. nathan: I just uploaded a small modification. Let me know if it takes care of the issue.

  54. 95
    nathan

    Further UPDATE: It’s only showing the Pages as part of the default category. The other categories work fine.

  55. 94
    nathan

    UPDATE: I tried limiting it to one post and then it sometimes posts one of the Pages instead of another post in that category. Interestingly, if there really are no other posts in the category, it shows nothing. I don’t understand why it seems to be adding a category to the Pages and displaying them.

  56. 93
    nathan

    Hi, this plugin is exactly what I need to create an easy internal “related links” at the end of each post. However, it is currently listing the posts in that category first (correct) and then Pages for the remaining links. How can I edit to only list posts?

  57. Adil: I may add an exclusion feature in the future. For now though, here is one way you can do it.

    Replace this line in the script:

    return $content . ddop_show_posts();

    With this:

    $c_post = $post->ID;
    $c_cat = get_the_category(); 
    $c_cat = $c_cat[0];
    
    if (($c_cat == 1) || ($c_cat == 2) || ($c_cat == 3)) {
    	return $content . ddop_show_posts();
    }

    Where 1, 2, and 3 are the categories you want to allow. This could also be changed to display for all categories except the ones you specify like this:

    if (($c_cat != 1) && ($c_cat != 2) && ($c_cat != 3)) {

  58. Thank you for this plugin-I have been looking for this for some time and I like the way you’ve done it. Could you please make it possible to have more control over the categories chosen? For instance, I want to exclude some categories (I have some categories that are too general, others that divide posts according to volume/issue–I want to be able to list relevant posts according to categories that describe content only (for instance “international” “videos” “music” and not “Volume 9″. Thanks a lot–hope you have the chance to do this.

  59. “Is it possible to show content along with the Title using the_excerpt or the_excerpt_reloaded? I’m trying to make a two column page that shows only posts from the same category, and the only solution I can find is your plug-in on the left, and a loop on the right column with an offset by the number in the left.”
    I’m interested to. Pls mail me:)

  60. Saman: Fixing now :)

  61. I just wanted to let you know that, on v.1.3, when you’re in the plugin’s config page, it says it’s version 1.2!

  62. John: Sure. Find this line:

    AND post_status = 'publish'

    And after it add this:

    AND post_date < NOW()

    (you have to do this twice, look for both instances of that line)

  63. Thanks for this plugin. I just installed it and it seems like it’s going to work out nicely. I just have one little issue that I’m surprised no one else has caught yet.

    I write a lot of my posts in advance, and the plugin is displaying links to upcoming posts, which of course people cannot get to just yet.

    Is there a way to change it so that it does not show future dated posts?

    Thanks,

    John

  64. Very nice plugin, it’s indeed a useful tool for my blog, thank you so much

  65. Preetinder: The function currently has to be ran from the loop, which is why it will not work in the sidebar.

    Daiv: Yes, there is an issue with this. I made mention of it in the article above. It works best when you are only assigning one category to each post.

    Ken: Yes that is possibe. Check your email.

  66. Is it possible to show content along with the Title using the_excerpt or the_excerpt_reloaded? I’m trying to make a two column page that shows only posts from the same category, and the only solution I can find is your plug-in on the left, and a loop on the right column with an offset by the number in the left.

  67. Ref comment # 78, I did the work around of deactivating the multiple categories option in admin. There seams to be a problem with multi cats, perhaps when there is only one cat. other posts plugin is working very well, Thanx so much for your efforts / hard work.

  68. Great Plugin.

    How do i display latest posts in current category in sidebar ?

    I want to display all the posts under the current category in sidebar.

    If i just place this code in sidebar

    
    <?php echo ddop_show_posts(); ?>
    

    it will show wrong category posts.

    I know it works if it is used in the loop, but isn’t there any way to grab the category id by placing some code in loop and displaying links outside the loop ?

    Any help will be highly appreciated.

  69. [...] my favourites. Here are some I am using: Fuzzy Recent Posts Plugin For WordPress | Semiologic Other Posts from Cat plugin for WordPress · Dagon Design SEO Title Tag: A WordPress Plugin for SEO (Search Engine Optimization) Neato » Blog Archive » [...]

  70. Daiv: Something else you can try - instead of using that mod, replace this code:

    if (mysql_num_rows($cat_list)) {
    	$ddop_other_cats = FALSE;
    }

    With this:

    $ddop_other_cats = FALSE;

  71. Hi, great plugin, it seams to be working for me, presents the lists of posts. But I am getting an error;
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /site/wp-content/plugins/dd-posts-from-cat.php on line 195
    I have the latest WP and your file from above, I’ve tried the suggested hack: if ((count($cat_list) > 0) && (mysql_num_rows($cat_list))) { It then displays the various Cats and post lists, but I get the same error.

  72. Thanks. It worked great!

  73. Turker: You can insert the following code into your template file. Just make sure it is within the ‘loop’:

    <?php echo ddop_show_posts(); ?>

  74. Hi. Thanks for this great plugin.

    I’d like to integrate this into my current theme. I don’t want the titles to show up UNDER the posts but NEXT TO them. And I don’t want to manually configure this for every single post, by writing for each post.

    I tried to include this in the single.php but it didn’t work.

    How can I make it?

    Thanks.

  75. Rod: You can place it wherever you like. By default, it is added to the bottom of the posts, but if you prefer, you can use the trigger text in your post or page to manually specify the position:

    <!-- ddpostsfromcat -->

    Of course, if you want it aligned to the right for example, you could wrap it in a div, which is styled to float to the right, etc..

  76. OK, all is right. Your plugin is very fantastic … my english is quite bad, and some of your options were not easy to understand when you don’t speak like Shakespeare :) So … the only thing which misses to your plugin, is the possibility to put where you want (in my example : on the right of the post)

  77. ahahah first comm’ and great Newbie attitude I had !!! :) OK for the options of “all categories” … it would be nice so to separate each category instead of a list of “all” :)

    So … the only thing which is wrong is the code which doesn’t work if I want to place the list somewhere else.

  78. doesn’t work for me …
    1. first problem : if I chek “show under the post” … I choose 5 post … and I have in H2 > “The last 5 articles from “Category” … and I have not 5, but 10 :)

    2. The worst : I WANT to place when I want inside the post page (and whynot the index, but in this case, the post page) the code … and … it’s not interpreted. When I see the source, I see :

    
    <dt>Derniers articles</dt>
    <dd> <!-- ddpostsfromcat --> </dd></dl>
    

    So … I’m on WP 2.1.2 and php5.2 . A feature would be great : you have the choice between the “current” category and “all” categories. But if I take my example (a post inside 2 or 3 categories in same times, for example : Bars, Concerts, Photos … it would be nice to have an option to list the xxx posts from each category where the post is. Possible ?

  79. João: It is, but you have to modify a couple of things. First you need to add a parameter called $c_cat to the ddop_show_posts function, and remove the two lines near the top of that function which set $c_cat. Then call the function like this:

    <?php echo ddop_show_posts(123); ?>

    There is also a declaration of $c_post in the function, which you will just need to set to 0.

  80. Great Plugin!

    As a newbie, I was wonderng if it is possible to call the function from outside the loop , specifying the category, such as .

    As I understand i can call the php functions to some other file, and execute the query, but it must be to an specific category?

    Thanks!

  81. Cent: Here is something you can try. Change this line in the script:

    if (mysql_num_rows($cat_list)) {

    To this:

    if ((count($cat_list) > 0) && (mysql_num_rows($cat_list))) {

    As far as the sidebar, this plugin has to be executed within the actual post loop so it will know what post is being displayed. It will not work properly in the sidebar since it will not within the loop, and cannot see the post data needed.

  82. 67
    Cent

    Hi. Just installed this plugin on WP 2.1. Two things… The plugin is installed fine and shows the other posts in the same categories fine. However, just where the post begins on my single.php page, I get the following error:

    Warning: mysql_num_rows(): supplied argument is not a valid 
    MySQL result resource in /home/virtual/site2/fst/var/www/html/
    content/wp-content/plugins/other-posts-from-cat.php on line 195
    
    Warning: mysql_num_rows(): supplied argument is not a valid 
    MySQL result resource in /home/virtual/site2/fst/var/www/html/
    content/wp-content/plugins/other-posts-from-cat.php on line 195

    However, the plugin does seem to be working as it shows the other posts at the bottom of the current post.

    My 2nd question is, I don’t want to show these categories and other X posts from them at the bottom of my main post, but in the sidebar. How can I do that?

    Thanks
    Cent

  83. Merkal: It would be possible yes, but the plugin currently uses a single list of posts and they are not separated by category.

  84. Fine plugin just what I needed for, The admin tab is a great addition too. Now my question is about the option to output post from multiple cats. Is it possible to get to lists next to each other instead of under each other? Perhaps with CSS floats or by using good old tables. thanks

  85. John: I just uploaded version 1.3 - let me know if it fixes the issue for you. It looks like when the option was set to search other categories the post is in, but it is in no others, it was not processing the category list properly.

  86. The () comes from here:

    
    if ($ddop_other_cats && !$ddop_sep_cats) {
    
    	// show other cats too, but in one list
    
    	$category_check = " WHERE (";
    		
    	$i = 1;
    
    	foreach ($cat_list as $c) {
    
    		$category_check .= " category_id = " . $c->cat_ID . " ";
    
    		if ($i < sizeof($cat_list)) {
    			$category_check .= " OR ";
    		}
    
    		$i++;
    
    	}
    
    	$category_check .= ") ";
    

    The $category_check is throwing an error and that’s why the () ends up empty.

  87. John: Hm.. that WHERE line should not just have an open and close parenthesis after it like that. It looks like that is causing the error. You can remove the () and the AND right after it, so it looks like: WHERE wp_posts.ID etc..

  88. I’ve tried !=, and NOT IN (7,8) - all produce the same error:

    
    WordPress database error: [You have an error in your SQL syntax; 
    check the manual that corresponds to your MySQL server version
     for the right syntax to use near ') 
    			AND wp_posts.ID = wp_post2cat.post_id 
    			 AND ID != 59  
    			AND post_s' at line 3]
    
    			
    			SELECT DISTINCT ID, post_title, post_date, post_category
    			FROM wp_posts, wp_post2cat 
    			 WHERE () 
    			AND wp_posts.ID = wp_post2cat.post_id 
    			 AND ID != 59  
    			AND post_status = 'publish' 
    			ORDER BY post_date  DESC  
    			LIMIT 5
    

  89. John: Some versions of MySQL use <> instead of != but if one works for you, more should work too.

    Also, make sure there is a space at the end of those lines in the query string, or it may not be separating them properly. Did the error message give any other information?

  90. I was trying to do something like that before but didn’t have the ‘Check all categories that current post is in’ box checked. Now it is but I’m getting a MySQL syntax error when I try to exclude more than one category (as per your example). If I have:

    
    WHERE post_id = {$c_post}
    AND cat_ID !=7
    AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    

    it’s OK, but as soon as I do this:
    
    WHERE post_id = {$c_post}
    AND cat_ID !=7
    AND cat_ID !=8
    AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    

    I get: “You have an error in your SQL syntax”

  91. John: Find this line in the script:

    // get list of cats this post is in

    Directly after it is a SQL query. After the WHERE line, add in something like this:

    AND cat_ID != 1 AND cat_ID != 2

    That should do it :)

  92. I notice this in the plugin script:

    $ddop_excluded_cats = get_option('ddop_excluded_cats');

    but it doesn’t appear to be used anywhere else. How do I go about implementing excluding certain categories?

  93. hello! great plugin! i was wondering how to turn off the default placement under posts coz i want it in the sidebar. thank you! :)

  94. 55
    museum

    Looks great but I’ve to wait to the missing too before use it really…

  95. Thanks Maira - I’ve managed to install WP in Spanish and customize your version of the plugin too!

    Admin: thanks for the “get posts” tag info - it’s just what I needed to round off my site. In fact I came here looking for something like that and found your plugin which is a way better option!

    Hey, what about the missing DIV in the plugin? Or am I the one that’s missing it? :-s

  96. maira: Thanks, I just uploaded the new copy here as well :)

    Aaron: If you just want a listing of the latest posts from a couple of categories, you do not really need a plugin. Try this: http://codex.wordpress.org/Template_Tags/get_posts

  97. Is it possible to use this plugin more than once? E.g. by changing the function names in the plugin? I need to show the latest 5 posts from two different categories on an Index page, but I am already using the plugin for a separate job (and it’s working admirably!). Thanks.

  98. 51
    maira

    Jorge: I think I forgot to put the files in their own folder. You should create a folder named ddop under your plugins directory and place dd-posts-from-cat.php and ddop-es_ES.mo inside it.

    The zip in http://cachuflos.net/wp-content/uploads/ddop.zip has been updated accordingly.

  99. Oops - I forgot: the DIV that is mentioned in the documentation doesn’t seem to be output by the code. I’ve found a workaround (including the plugin after the post, inside its own div) but I’m suppose it’s an easy fix for Admin :-)

  100. Thanks for the plugin! I’m still new to Wordpress. I installed the international version but I don’t know how to enable the Spanish translation or how to make the dates appear in Spanish. I’ve resorted to using numbers for the time being. Any pointers will be much appreciated.

  101. Maira: Thanks :) I am adding it to the site right now.

  102. 47
    maira

    I have fully internationalized your plugin, it now show the dates in the appropiate language. I’d send you the files but I couldn’t find your e-mail, so you can download them here: http://cachuflos.net/wp-content/uploads/ddop.zip

    Files: dd-posts-from-cat.php, ddop.pot, Spanish .po and .mo

  103. [...] You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your ownsite. [...]

  104. Ahh, sorry, I feel so silly, I just realised there was more than one page of comments, and found the answer on one of those. Thank you anyway, I will be sure to mention this excellent plugin to my friends!

  105. Hi, does anyone know if it’s possible to use this plugin outside of having it in a post? I need a way of doing this, but putting it in a sidebar in a specific single.php to call the titles of the other posts in the category. Any advice would be great! Thanks.

  106. He, I knew it wasn’t going to work but I just had to try… Ok, if there’s someone interested, I’ll come back again and do my best to post the code.

  107. Thanks for this!

    Just in case someone is interested, I’ve changed some code to show a “(View all)” link at the bottom of the list:

    line 341 $the_output .= '<a href="' . get_category_link($curr_cat_id) . '" rel="nofollow">(View all)</a>';

    line 348 $the_output .= '<a>cat_ID) . '"&gt;(View all)</a>';

    You can vew it at http://cachuflos.net/ciro/ (in Spanish and always under construction).

  108. you rulez man.
    helped me to put the list on a new sidebar.

  109. yeah, I already understood that :) but didn’t knew about the “loop”.. oki will try to modify it on my own.. :P

  110. Dimitridze: The reason it will not work is because the plugin has to execute within the main wordpress ‘loop’, otherwise it will not know what category you are currently viewing. There are options, but it really just depends on how your template is written. A modification of this script (if it would still work depending on the situation) would be neccesary. :)

  111. What if I want the list to be outputed outside Post’s ? I’ve tried call the “ddop_show_posts();” function outside manualy, but it didn’t work..

    your other function “ddop_generate” is processing $content variable, so it’s no use for me..

    can u help? or mb i ought to find another plugin.. :/ i dont want the list to apear within posts, but after it..

  112. [...] 這個 Other Posts From Cat 還蠻常見的,就是在文章後附上和這文章相同類別的最近 n 筆文章 ~ [...]

  113. Fantastic plugin - thanks!

  114. [...]   日志现在用上了Other Posts From Cat这一个插件,它可以在每篇日志底部列出跟该日志分于同类的其它日志。使用起来非常方便,在后台激活就行,所有更改都在后台完成,不用改代码文件。而且,也可作为相关日志插件Related posts的代替。推荐使用! [...]

  115. 34
    Sparanoid

    Great plugin, and can it shows only the older posts in the same cat. than the current post?

  116. Andy: Check out the new version (1.2) I just uploaded ;)

  117. Admin: It’s sort of what is expected. If more than one category, it says, for instance, Last posts in X Cat, Y Cat, Z Cat, and lists them al together.

    Thanks for the modification

    What I meant is is it possible to have it work like this when more than one category:

    “Last ? Posts in X Category:”
    -post
    -post
    -post
    -post
    -post

    “Last ? Posts in Y Category:”
    -post
    -post
    -post
    -post
    -post

    and so on.

    Thanks again though! :D

  118. Andy: Check out the new version :) It includes an option to show recent posts from all categories the current post is in. I have tested it, but not that much, so let me know if it works for you :) (the option is disabled by default, be sure to enable it).

    MoiMM: I have added a CSS class around the output. More information is in the article above :)

  119. Andy: Even just a link would be fine :)

  120. Admin: Much appreciated. How would you like me to credit you on my website?

  121. MoiMM: This plugin does not use any CSS classes around the output. I will see about adding some in though :)

    Andy: I will see what I can do :)

  122. Admin: Yes, show the last X posts from the categories this post is in. I’m assuming it wouldn’t be too difficult!

    Thanks for the plugin again.

  123. Hello !

    Nice Plugin !

    I just want to know how i can change (or add) the CSS !?

    Sorry my english is very bad ! :)

    Thanks

    :)

  124. Andy: If you added too many categories, it would just be a ‘recent posts’ plugin ;) But seriously, it would be possible. In other words - show the last X posts from the categories this post is in - right?

  125. Is it possible, or even likely, that you could create a version of this plugin that was capable of showing the last X posts for more than one category when more than one is assigned to a post?

    Or allow the user to choose which category, if more than 1, is displayed at the bottom of each post?

    Nice work though

    Andy

  126. That works. Thanks again for a terrific plugin.

  127. Oliver: The best solution for you might be to just call the function directly from the template file, where you want the links to go:

    <?php echo ddop_show_posts(); ?>

  128. Hello there,

    Great plugin. But it doesn’t seem to display the links if the single.php template is changed to use an alternative to the_content.

    I’m trying to stop WP from applying the texture filters by getting my content before it’s filtered. For example, if I replace the_content with echo get_the_content or echo $post-&gt;post_content, I’ve successfully bypassed the automatic text formatting, but your plugin stops displaying links.

    I’ve tried editing the plugin, modifying add_filter('the_content', 'ddop_generate'); to correspond to the applicable alternative mentioned above, but still no links are displayed. (Though, admittedly, I may be barking up the wrong tree here.)

    And as long as I’m thinking wishfully, how about a way to display the links _after_ the postmetadata?

    Thanks a bundle for all your effort to date.
    http://www.ardamis.com/

  129. [...] For a while I’d been wondering about how to list the most recent post from each category on my WordPress home page. I kept my eyes open for a solution but found none, and not been adept at PHP I wasn’t up to creating one myself. In my search I came across Admin’s Other Posts from Cat plug-in, which shows the last X posts from the current category at a location of your choice. It seemed to have vaguely similar underpinnings to my requirement, so I sent Admin a message on 31 May: Subject: DD Contact:New WP plug-in idea? [...]

  130. 19
    gaga

    Thanks in advance, that works!!

  131. gaga: That is not a valid function name. To manually display the data within a PHP file (such as your sidebar), use this code in sidebar.php:

    <?php echo ddop_show_posts(); ?>

  132. Hai,
    I’m a beginer, and I would like to put your plugin in my website.
    I have wrote in sidebar but it doesn’t work -Call to undefined function: ddpostsfromcat()- could you please help me on this issue

    Thanks a lot
    gaga

  133. I think your code got a bit messed up because the code block was not closed properly. I see what you were saying though.

    You are correct. The current version of this plugin only checks the first category a post is listed under. I wrote above: “This means that it will work best for those of you who only assign one category to posts.” :) Otherwise it would be called the ‘Other posts from all categories this post is in plugin’. j/k ;)

  134. Ooops, I spoke a little too soon. The code you suggested only excluded the plugin from displaying anything if the first category was the one in the if statement. I wanted it to skip that category and list for the next category the post is listed under. (Also, it could be useful to list the latest posts in other categories that the posts belongs to also for multi-category posts, but I didn’t implement that. It would require a loop).

    I added a little more code and shifted the position of the code to go before the header so the proper category name would be displayed. Here is the code:

    
    	$c_post = $post-&gt;ID;
    	$c_cat = get_the_category(); 
    	$c_cat = $c_cat[0];
    
    	$curr_cat_id = $c_cat-&gt;cat_ID;
    	if ($curr_cat_id == 5) {
    	$c_cat = get_the_category(); 
    	$c_cat = $c_cat[1];}
            $curr_cat_id = $c_cat-&gt;cat_ID;
            if ($curr_cat_id == 5) return "";
    
    	// fix up header
    	$ddop_header = str_replace('%C', $c_cat-&gt;cat_name, $ddop_header);
    

  135. Thanks, that works well!

  136. Mark: Sure. Here is one way. Find this line in the script:

    $curr_cat_id = $c_cat->cat_ID;

    After it, add this:

    if ($curr_cat_id == 30) return "";

    Where 30 is the id of a cat you want to exclude. You can duplicate this line for other cat ids as well. It is not the most elegant way, but it works ;)

  137. Nice plugin!

    Is it possible to exclude a certain category from displaying? Most of my posts are under one top category and then subcategories underneath and I want to exclude the category that they all belong to so I can highlight the subcategory related posts.

    Thanks!

  138. Jade: Glad you like it :) Thanks.