bioneural.net site preferences

Accessibility

Toggle width/ text size:

style

Default/Alternate

Suits visual impairment, mobile devices

Styling

Change the theme:

layout

NB: may reduce functionality

Link behaviour

Links with an icon are off-site:

links

Right-click any link to optionally open in a new window or tab


Listing the latest post from each category

One of the nice things about WordPress is the large community of enthusiasts who both use and develop for it. If you're stuck, the chances are high someone can help you. If you have a particular requirement, chances are that someone has written a plug-in that does just what you want. And if there is no plug-in, someone might just make one if you ask nice...

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 Aleister'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 Aleister a message on 31 May:

Subject: DD Contact:New WP plug-in idea?

I came across your plug-in while Googling for a way to do the following:

On the homepage, list only the most recent post from each blog category.

Sounds simple, but I can't find any plug-in or hack to do this. Feel like a challenge? ;-)

On the same day, Aleister wrote back saying version 1.0 was "All done ;)"

Wow—that's some response! You can download the said plug-in here, which is described thus:

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, as well as other options.

I'm ashamed to say it took me three days to try it out (I was focussing on Gallery). It's supremely easy to use and it works well. I tried it using my K2-based theme with this code in sidebar.php:

<?php if (is_home()) { ?>
<div class="sb-latestcat"><h2><?php _e('Latest in each category'); ?></h2>
<?php echo dd_last_from_each(); ?>
</div>
<?php } ?>

It looked like this (dates disabled; no heading text):

Latest-Sidebar

I also inserted it at the top of loop.php, to make it appear at the top of the home page:

<?php /* If this is the frontpage */ if (is_home()) { ?>
<div class="latestcat"><h2><?php _e('Latest in each category'); ?></h2>
<?php echo dd_last_from_each(); ?>
</div>
<?php } ?>

Unstyled, with the same plug-in settings (Dashboard > Options > DDLatestFromEach) it looked like this:

Latest-Loop

Great work Aleister and many thanks!

Feature request: hyperlinks to category names (as per "Category feeds" in my home page sidebar). He's a mover, this guy Aleister!

7 responses to “Listing the latest post from each category”


  1. 1 Aleister

    I noticed your feature request at the bottom of this post and released version 1.2 of the plugin.

    It now includes an option to turn the cat names into links ;) Enjoy!

  2. 2 Mary-Ann Horley

    I'd love to see something like this that incorporates the excerpt - I'm displaying the latest post from each category on my site but I'm doing it with lots of mini loops and I don't think it's very efficient. I'd also like to have the newest post at the top.

  3. 3 Bruce

    Mary-Ann, the plug-in options let you choose to include the first X characters of each post (which could give you a taste or all of your excerpt), and sort by date or by category.

  4. 4 Mary-Ann Horley

    OK, that would be good but I've got photos in my excerpts and I guess it doesn't show them?

  5. 5 Bruce

    That's correct Mary-Ann (I just tried it), although looking at the plug-in code I'm assuming you could simply edit out strip_tags to display HTML instead of text, thus showing your pictures.

  6. 6 Mary-Ann Horley

    Sweet, I'll try it. Thanks!

  7. 7 Adinel

    Ok, but what about displaying multiple articles from each category. So, instead of only one post by category to have n posts.

    Thanks, I am looking for that in months!

    Anyway, this plugin is the closest I got and it's great :)

Something to say?

Comments may be moderated (e.g. no commercial promotion), are subject to spam filtering, and should be relevant to this post—otherwise make contact.

Usable tags include <a href=""> <blockquote> <em>. Select any text and click to quote.