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.92   Updated Tuesday, July 7th, 2009 at 6:18pm

Latest Post from each Category plugin for WordPress

This plugin displays a list of the latest post from each category of your WordPress installation. It can be added to a post or page, or used directly in a template file. In the plugin’s options page you can choose the sort order, show or hide the dates, select the date formatting, show the first X characters of the content, display a link to the comments, and show comment counts, as well as other options.

Download

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

Installing

  • 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 DDLatestFromEach).

Using

There are two ways you can use this plugin.

1) In a post or page, insert the following line:

<!-- ddlastfromeach -->

2) In a template file, insert the following code:

<?php echo dd_last_from_each(); ?>

Change Log

  • 07-07-09 Version 1.92 – Slight change to the way the list is displayed.
  • 07-06-09 Version 1.91 – You can now choose how many posts per category to display.
  • 02-19-09 Version 1.9 – Added option to use only selected categories.
  • 08-14-08 Version 1.8 – Tested with WordPress 2.6. Now uses WordPress function for determining date/time to show up to date posts. Added option to exclude categories.
  • 09-27-07 Version 1.7 – Updated to support WordPress 2.3. Added ‘Load Default Options’ button.
  • 05-31-07 Version 1.6 – Better support for international date formatting
  • 05-16-07 Version 1.5 – Updated for WordPress 2.2
  • 02-20-07 Version 1.4 – Updated for WordPress 2.1 (new pages were showing up in the default category)
  • 08-09-06 Version 1.3 – Added options to show comment links and counts. Also added an optional limit to the number of links shown, and a few other fixes.
  • 06-03-06 Version 1.2 – Added an option to turn category names into links. A bug was also fixed where extra slashes were being shown in the header text.
  • 05-31-06 Version 1.1 – You can now choose the sort order of the output, hide password-protected posts, and show the first X characters of the content after each post. A few other fixes have been made as well.
  • 05-30-06 Version 1.0 – First release.

Demo

Here you can see the plugin in action:

Latest Post From Each Category

Options

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

Header text

This is shown above the list of posts.

Sort order

You can choose to have the data sorted by category or date. You also have the option of ascending or descending on both.

Show link to comments

When enabled, this will add a link to the comments for each post listed.

Include number of comments

This option only applies if Show link to comments is enabled. It adds the number of comments to the comment link.

Include link for posts with no comments

This option only applies if Show link to comments is enabled. It allows you to include or hide the comment link for posts with no comments.

Turn category names into links

Enabling this option will turn category names into links to the categories.

Hide password-protected posts

This prevents password-protected posts from showing up.

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)

Show first X characters of posts

This allows you to show a preview of the content under each post in the list.

Number of characters to show

This lets you specify how many characters of the content will be shown, assuming you have the previous option enabled.

Limit list to X categories

This allows you to set a limit on the number of categories that will be shown in the list. Set to 0 for no limit.

Excluded category IDs

This is a comma-separated list of category ID’s you want excluded from the list.

Included category IDs

This is a comma-separated list of category ID’s you want to use in the list. This option only applies if you are not using the excluded category IDs option.

Max posts per category

If you would like to show more than one post per category, you can change the number here. To display all posts, use 0.

Pages: « 2111 10 9 8 7 6 5 [4] 3 2 1 » Show All

  1. karl: It would be possible, but that would be a completely different purpose than what this plugin was made for. :)

  2. Karl: If you email me directly I might be able to help you do this another way. One way would be to use a plugin I made to display the most recent post from one category only. I could modify my plugin to display all post if it is necissary.

    It would help to know what else you are trying to do on the same page. You can click on my name to visit my website and see if its something you are interested.

    My email is (stoi2m1) [at] {yahoo} /dot\ .

    Jesse

  3. 58
    karl

    can you modify this to show all posts within a particular catagory?

    So if I mark a post “foo” all my previous foo related posts would display?

  4. Jessee: I received it. It is just a lot of code to look through and sort out :) I will though.

  5. I sent you an email about my MODs. Im not sure if it was the right email. It was the one that sent me an email from this post.

    Let me know if you got or if I need to resend it.

    Thanks,
    Jesse

  6. Jesse: By ‘article’ I mean my actual post above. Do not worry about the introduction then – feel free to email me the information :) Thanks.

  7. 54
    Jesse

    Im not sure what article you are talking about here. And Im not sure how to write an introduction. Would you like me to put together what I have done and then email it to you. I can put together a text document with some info in the format of an outline or an index. Following that I can list the mods with some info on how each one is works and what they are doin, similar to the way I posted it. Let me know what you think. Now is the time for me to do this, its still fresh on the mind and Im traveling on buisness so Im not dealing with family life right now.

  8. Jesse: Nice work :) If you want to write a little introduction for it, I will add the info to the article.

  9. 52
    Jesse

    This is a correction to post 51. Mod 5 and Mod 6 ended up blending together.

    **MOD 5 filters out the sub-categories**
    -origional function
    $last_posts = (array)$wpdb->get_results(”
    SELECT post_date, ID, post_title, cat_name, cat_ID
    FROM {$table_prefix}posts, {$table_prefix}post2cat, {$table_prefix}categories
    WHERE {$table_prefix}posts.ID = {$table_prefix}post2cat.post_id
    AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    AND {$table_prefix}categories.cat_ID 2
    AND post_status = ‘publish’
    AND post_date 2
    -This causes the the search to look for categories that have a category perant of 0 meaning they have no perant
    $last_posts = (array)$wpdb->get_results(”
    SELECT post_date, ID, post_title, cat_name, cat_ID
    FROM {$table_prefix}posts, {$table_prefix}post2cat, {$table_prefix}categories
    WHERE {$table_prefix}posts.ID = {$table_prefix}post2cat.post_id
    AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    AND {$table_prefix}categories.cat_ID 2
    {$table_prefix}categories.category_parent = 0
    AND post_status = ‘publish’
    AND post_date get_var(“SELECT post_content FROM ” . $table_prefix . “posts WHERE ID=” . $posts->ID);
    $the_output .= ”;
    $the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
    if (sizeof(strip_tags(trim($the_text))) > $ddle_chars) {
    $the_output .= “…”;
    }
    -The new code
    if ($ddle_excerpts) {
    $the_text = $wpdb->get_var(“SELECT post_content FROM ” . $table_prefix . “posts WHERE ID=” . $posts->ID);
    $the_output .= ”;

    if ( strlen(strip_tags(trim($the_text))) > $ddle_chars) {
    $the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
    $the_output .= ” … ” . ‘ID) . ‘”>[More]‘;
    } else {
    $the_output .= $the_text;
    }

    $the_output .= ”;
    }

  10. 51
    Jesse

    Here are the mods that I have implemented into this plugin.

    Andy I think MOD 1 will answer your question.

    I have not made these mods accessible from the options menu. There is no need for me to be able to change these option. So look at the Origional Code and then my Current Code then determine whats going on to make your own changes.

    Heres a link to http://www.stormscorner.com/ewb the lower section of the homepage is being produced by the latest_post_from _category plugin.

    
    **MOD 1. This keeps a certain category from listing**
    
    -In the script, find this line:
      AND post_status = 'publish' 
    -Right above it, add this line:
      AND {$table_prefix}categories.cat_ID  3
      (Where 3 is the category ID) 
    
    **MOD 2. adds a sapce between posts**
    -Origional code
      $the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
      $the_output .= '';
    -New code
      $the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
      $the_output .= '';
    -Added the second  to this line of code
    
    **MOD 3. fixes the situation of having only one comment, origional code does not adress if there is only one comment**
    -This mod also rearranges the Comment output code to match my theme.
    -Origional code  
      if ($ddle_comment_num) {
        $the_output .= $num_comments . ' Comment';
    
        if ($num_comments != 1) {
          $the_output .= 's';
        }
    
        } else {
          $the_output .= 'Comments';
      }
    
    -It now looks like this
      if ($ddle_comment_num) {
        $the_output .=  '   [Comment';
    
        if ($num_comments != 1) {
          $the_output .= 's ('.$num_comments.')]';
        } else {
          $the_output .= '('.$num_comments.')]';
    
      } else {
        $the_output .= 's ('.$num_comments.')]';
      }
    
    **MOD 4. changes the output format**
    -Origional Code
    $the_output .= '</b>: <a>ID) . '"&gt;' . $posts-&gt;post_title . '</a>';
    if ($ddle_show_date) {
    			$the_output .= ' - ' . date($ddle_date_format, strtotime($posts-&gt;post_date));
    		}
    -I made it look like this, 
    $the_output .= '</b>: <a>ID) . '"&gt;' . $posts-&gt;post_title . '</a>';
    if ($ddle_show_date) {
    			$the_output .= date($ddle_date_format, strtotime($posts-&gt;post_date));
    		}
    -Adding the  to the end of the first line allowed me to setup the format to match the rest of the page
    -removing the ' - ' . removed the - from the beggining of the date and comment line
    
    **MOD 5 filters out the sub-categories**
    -origional function        
    		$last_posts = (array)$wpdb-&gt;get_results("
    		SELECT post_date, ID, post_title, cat_name, cat_ID
    		FROM {$table_prefix}posts, {$table_prefix}post2cat, {$table_prefix}categories 
    		WHERE {$table_prefix}posts.ID = {$table_prefix}post2cat.post_id 
    		AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    		AND {$table_prefix}categories.cat_ID  2
    		AND post_status = 'publish' 
    		AND post_date  2
    -This causes the the search to look for categories that have a category perant of 0 meaning they have no perant
    		$last_posts = (array)$wpdb-&gt;get_results("
    		SELECT post_date, ID, post_title, cat_name, cat_ID
    		FROM {$table_prefix}posts, {$table_prefix}post2cat, {$table_prefix}categories 
    		WHERE {$table_prefix}posts.ID = {$table_prefix}post2cat.post_id 
    		AND {$table_prefix}categories.cat_ID = {$table_prefix}post2cat.category_id
    		AND {$table_prefix}categories.cat_ID  2
    		{$table_prefix}categories.category_parent = 0
    		AND post_status = 'publish' 
    		AND post_date get_var("SELECT post_content FROM " . $table_prefix . "posts WHERE ID=" . $posts-&gt;ID);
    	$the_output .= '';
    	$the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
    	if (sizeof(strip_tags(trim($the_text))) &gt; $ddle_chars) {
    	$the_output .= "...";
    }
    -The new code
    if ($ddle_excerpts) {
    	$the_text = $wpdb-&gt;get_var("SELECT post_content FROM " . $table_prefix . "posts WHERE ID=" . $posts-&gt;ID);
    	$the_output .= '';
    				
    	if ( strlen(strip_tags(trim($the_text))) &gt; $ddle_chars) {
    		$the_output .= substr(strip_tags(trim($the_text)) , 0, $ddle_chars);
    		$the_output .= " ... " . '<a>ID) . '"&gt;[More]</a>';
    	} else {
    		$the_output .= $the_text;
    	}
    
    	$the_output .= '';
    }
    

  11. Alternatively, is it possible to exclude a category?

  12. Hehehe!

    You sent me some code so I could have the latest post, no matter the category, showing on a page. Shall I forward it to you in email?

    Thanks

  13. Jesse: Feel free :) I will update this script again eventually, but things have been crazy lately!

    Alborz: Try this:

    <?php echo dd_last_from_each(); ?>

    Andy: I do not even remember what I send you :)

  14. Hi again Admin!

    It’s been a while, but I have been very busy with the new baby! hehe

    I now get this error when trying to use the code you sent me:

    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 '' at line 1]
    SELECT post_content FROM abblogwp_posts WHERE ID=

    Any ideas?

    Thanks

    Andy

  15. Hey mate,
    I have been able to modify the code well enough so that it displays from only one category (the way I want it) but I can’t get it to work in my sidebar, do you know how I can call the function from there?

    Thanks.

Pages: « 2111 10 9 8 7 6 5 [4] 3 2 1 » Show All

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.