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 Friday, February 20th, 2009 at 7:19pm

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.8+)
  • 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 higher!

  If you have found this page useful, please consider donating. Thanks!

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. An update: we checked the option to show it within posts to prove it works, and it works in the sidebar on other pages (pages for tags and categories), but it doesn’t show on single pages.

  2. Hi, very nice plug-in, just what we needed for more page views. There are a few problems though. We tried to use it in combination with another plug-in in order to show yours in sidebar only on single pages (with a title). Since it didn’t work we used your code in order to test it, and it worked for a while and stopped showing later on. It is working within the posts/articles (that option is unchecked for now).

    <?php echo ddop_show_posts(); ?>

    Another problem we noticed is that it doesn’t show posts from other categories if the article is both in an Excluded Category and some other. Shouldn’t it show articles from other categories that aren’t excluded (in our example, Featured category is excluded since it is used to show Featured posts, but the post is both in Featured and Tech).

    Regards,
    Rob

  3. watch maharashtra assembly election news live on tv9 mumbai in <a href="http://www.snehatv.com" >www.snehatv.com </a>

  4. watch maharashtra assembly election news live on tv9 mumbai in http://www.snehatv.com/

  5. Hi Damian

    Thanks a lot for this plugin..It’s awesome. Even I had the problem with and now tried . It is displaying perfectly, but the styling is all gone. It is displayed in some really minute font. I am trying to enclose it some div tags to increase the font, but it is not working. Please help me with it, if you have time.

    You can check how it appears on my site URL.

  6. This plugin has been tested, and works in the latest release of WordPress – 2.8

    Jens: That function only returns the output, it does not display it. Try this:

    <?php echo ddop_show_posts(); ?>

    For those asking about the ability to sort posts alphabetically – this plugin is category based, and the code is not written to sort by post. There are other plugins out there that can generate an alphabetical listing of posts.

  7. Thanks for the hardwork guys, nice to see this plugin

  8. 181
    damian

    Welcome

    I use the plugin Other Posts From Cat and very dependent on me that the entries are displayed alphabetically, AZ

    Yours
    damian

  9. 180
    d4b

    How to sort the entries alphabetically, I care very

  10. thanks for this great an very useful plugin!

  11. How sort post ASC DESC ??? help me

  12. Soo how to get posts only from subcategory
    inside categorys post

  13. Hi, very nice plugin :)
    for littly modify
    please help me how to change code in dd-posts-from-cat.php file for
    in categorys posts show other post titles only from this cat-s subcategorys.
    I read the entire article but can’t find sollutions
    thank you

  14. Sorry, I forgot the code-tag. Here again, what I pasted in my single.php:
    <?php ddop_show_posts(); ?>

  15. Hi! I actually used your plugin and added it in the single.php like this:
    But it shows nothing as ouput. Do you know what could be the problem? I use v1.6 of your plugin and wp2.7.1… Thanks! Jens

  16. Hi

    I have been using this plugin for over a year now and has been soo very useful. I want to add an Adsense script between the post and the links generated by this plugin. Any idea how to do that? Please help..

  17. Great Plugin!

    I saw someone else ask how to make the plugin show posts randomly rather than most recent. I’m very interested in that too. Has anyone figured that out?

    ed

  18. thanks for this great an very useful plugin!
    i also use Gengo plugin, and i wonder how can i modify this plugin to work with several languages, because this version (1.6) doens’t filter only the posts with the selected language…

  19. 170
    nelson d'aires

    to all,

    somebody uses algo gengo plugin and found out how to adjust this query to the tables of gengo?

    $category_check = " WHERE {$tp}terms.term_id = " . $c->cat_ID . " ";
    
    				$last_posts = (array)$wpdb->get_results("
    					SELECT DISTINCT ID, 
    						post_title, 
    						post_date, 
    						{$tp}terms.term_id as post_category
    					FROM {$tp}posts, {$tp}terms, {$tp}term_relationships, {$tp}term_taxonomy  
    					{$category_check}
    					AND {$tp}posts.ID = {$tp}term_relationships.object_id
    					AND {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id
    					AND {$tp}term_taxonomy.term_id = {$tp}terms.term_id 
    					{$ddop_inc_current} 
    					AND post_status = 'publish' 
    					ORDER BY post_date {$newest_check} 
    					LIMIT {$ddop_num}
    				");	 

    thanks!
    nelson

  20. 169
    nelson

    hi,

    thanks for this great an very useful plugin!
    i also use Gengo plugin, and i wonder how can i modify this plugin to work with several languages, because this version (1.6) doens’t filter only the posts with the selected language…

    thanks!
    nelson

  21. Thanks Matt,

    I can understand the work load at the same time we have our family to look after. I have replied to your email with details you asked. please check that at your convenient time.

    Thanks,
    Vivek

  22. I do read the comments – due to the overwhelming number of questions/requests on all of the scripts I am not able to personally help everyone for free of course. Check your email though.

  23. Is admin reading this comments and request ?? I am not able to use this plugin on wp 2.6.2

    I am using Revolution Church 1.0 Version.

    I try it putting both, automatic and manually the code but nothing is appearing on post pages. What can be done ?

  24. This plugin has been tested in the latest release of WordPress (2.7.1)

  25. Great plugin guys and it works a treat

  26. Thanks for a great plugin!

    I’m using <?php echo ddop_show_posts(); ?>to display the latest posts in a sidebar.

    It works as it should though in one category cat_ID=2 (below) it shows the wrong category. There are nine categories in total though this happens only in this one category/archive page:

    http://rsc-web.rsci.com/thethink/category/joyous-gard-what-is-it

  27. not working for me , any reason , i have activated plugin and configure properly , still not showing any posts ??

    any suggestion , any other plugin whcih can show other post from same category ?

  28. I want to put this plugin at index.php page… how to do that ?

  29. yeah, same as RiZ, I would like to manually configure the placement of this within my template file.. is there a way to do this?

  30. 159
    victor

    I’m trying to use this plugin in combination with qtranslate. The output looks like this: [lang_en]News1[/lang_en][lang_fo]News1fo[/lang_fo]. Is there a way to make this two plugins work together?

    Thanks, Victor

  31. Thanks I’m using it now!

  32. 157
    David

    Nifty plugin! Is there way to specify where in your single.php template the cat posts display? The issue is that the cat posts keeps showing up before my tags list.

  33. Great plugin guys and it works a treat :)

    It was just what I was looking for on my website – http://www.ddwt.co.uk – where you can now see it in action!

    Thanks again!

  34. Hi There,
    Thanks for the plugin. I am using it in different sites.

    Is there a way to add the posts’ excerpts or the first X characters of posts just like in your “Latest Posts From Each Category” plugin?

    Thanks again and best regards.

  35. Is there any way to make this work in a template file rather than in a post?

  36. is there any way to set up multiple lists?

    ie to exclude different categories depending on the list

  37. Hi there,
    Know anyone how plugin to use if I want only a part of the article to be displayed? If someone want to read more there will be a “read more” link…
    On my blog right now is displayed all of article content and I don’t want this…
    I’m talking about the latest 10 articles displayed on the first page of my blog.
    I’m using Wordpress.
    Can anyone help?

  38. 151
    Jessica

    Hi, I’m sorry if this shows up twice, but my previous comment isn’t appearing for me any longer (it had said that it was awaiting approval) and it’s not here on the page, so I thought it might have gone missing.

    A client is using this plugin on all of her post pages as part of the main template and it works perfectly except the exclude categories which isn’t working at all. When I type in the category title “Article Index,” all of the categories disappear; when I try anything else (like the category’s number), all related categories display including the category I’m trying to exclude. What do I need to do to make the exclude category feature of the plugin work?

    Thanks!

    Jessica

  39. thank you for this great plugin! But I have problem it shows me:
    WordPress database error

  40. I’ve found a small problem, I don’t know if it appeared with the upgrade to WP 2.5. When choosing to display multiple categories, the list of posts shows repeated posts (i.e. if the previous post belonged to three categories, it’s shown three times).

    Would it be possible to fix this?

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

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

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

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

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

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

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

  48. 141
    EssenzZo

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

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

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

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

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

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

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

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

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

  57. 132
    anomy

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

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

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

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

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

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

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

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

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

  66. 123
    Олег

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

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

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

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

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

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

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

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

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

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

  76. 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(); ?>

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

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

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

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

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

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

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

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

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

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

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

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

  89. Philipp: I just uploaded a small change – let me know if it helps.

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

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

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

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

  94. 95
    nathan

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

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

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

  97. 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)) {

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

  99. “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:)

  100. Saman: Fixing now :)

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

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

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

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

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

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

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

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

  109. [...] 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 » [...]

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

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

  112. Thanks. It worked great!

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

    <?php echo ddop_show_posts(); ?>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  134. 55
    museum

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  153. Fantastic plugin – thanks!

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

  155. 34
    Sparanoid

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

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

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

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

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

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

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

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

  163. Hello !

    Nice Plugin !

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

    Sorry my english is very bad ! :)

    Thanks

    :)

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

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

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

  167. 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(); ?>

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

  169. [...] 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? [...]

  170. 19
    gaga

    Thanks in advance, that works!!

  171. 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(); ?>

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

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

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

  175. Thanks, that works well!

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

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

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

  179. COOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOL!

    Thanks for the quick reply. Yeah, I was trying to find the code where it says where to put it, but I guess I didn’t look hard enough. I understand only basic php, and now that you’ve pointed it out It seems obvious, then again, you did write the damn thing. Well it works great now and I’ll be sure to reference this site.
    Thanks!

  180. Jade: No problem. First, find the ddop_generate function in the file. Then replace this line:

    return $content . ddop_show_posts();

    With this:

    return ddop_show_posts() . $content;

    And it will show the output above the posts :) Just make sure you have your options set to display it on every page.

  181. Is there anyway to put the output at the top of the post rather than the bottom? Ideally it would be where the “previous , next” links are in the default theme. The only solution I have is to delete the preV/next tagS in the template, then place the tag at the top of my post and Float it right. But is there anyway I can call the output from the template so I don’t have to put the: in every single post ?

    I appreciate any input, and regardless. great plugin, THANKS!

  182. Sam: Very good! :)

  183. Thanks again for your help, Admin! I have the issue resolved. It was a conflict with a restrictions plugin I’m using. Thankfully, I decided a few weeks ago not to use that plugin, so the clash is a moot point!
    cheers
    SAM :)

  184. Thanks for your quick reply! I already tried both those options but still nothing was generated. Any other ideas?
    SAM :)

  185. Sam: The two main options are to either enable the plugin to display at the bottom of posts by checking the ‘Show at the bottom of every post’ setting in this plugins option spage, or manually insert this line in the post itself (not the template):

    <!-- ddpostsfromcat -->

  186. Hmm, looks like a great plugin! However, I’m not getting any output displayed on my posts. Does something specific need to be in the single.php template? WP 1.5.3-1beta.

  187. I’m always looking for different ways for readers of my blog to view the posts. Since I am a teacher of sorts, this provides a way to help the reader navigate once they read a post in one of my teaching categories. I hope it will be useful to them. Thanks.

  188. Another one that works exactly as outlined here, with no hassles at all to get up and running! Thank you!

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.