ThemeShaper Forums » Thematic


How to show time when listing recent posts

(6 posts)
  • Started 11 years ago by gnurf
  • Latest reply from flick
  • This topic is resolved
  1. this is not specifically a Thematic issue, but if someone could help me out I'd be grateful.

    I'd like to use a plug-in or widget that lists the headlines/titles of the most recent posts (just like the Recent Posts widget) but after the title I'd like the time when published to show.

    Anyone who knows any working plug-ins (I found some but they don't work with WP 2.9.x) or other solutions?


    Posted 11 years ago #
  2. Maybe Justin Tadlock's Query Posts widget?

    Posted 11 years ago #
  3. I tried it but cannot get the time to show, perhaps it's possible but I couldn't find any hints in the very short readme, so further help and tips are appreciated.


    Posted 11 years ago #
  4. @gnurf: Apologies. It seems Query Posts doesn't offer this function after all.

    I tried out YD Recent Posts widget as it offers a way of customising the date function, but for some reason it didn't display properly for me.

    So I decided to opt for this code from Lesterchan's forums with PHP Code Widget and after checking the Codex documentation on formatting the_time, ended up with:

    <?php $my_query = new WP_Query('showposts=4');
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    if (strlen(the_title('','',FALSE)) > 80) {
    $title_short = substr(the_title('','',FALSE), 0, 80);
    preg_match('/^(.*)\s/s', $title_short, $matches);
    if ($matches[1]) $title_short = $matches[1];
    $title_short = $title_short.'...';
    $title_short = the_title('','',FALSE);
    <li><a title="<?php echo the_title() ?>" href="<?php the_permalink() ?>"><?php echo $title_short ?></a><span><small><?php the_time('F jS, g:i a') ?></small></span></li>
    <?php endwhile; ?>

    which seems to work ok for me - this particular snippet truncates the post title if it's too long.

    I'm sure it's possible to build your own widget on the basis of this code rather than using PHP Code Widget as well.

    Posted 11 years ago #
  5. Works like greased, thanks!
    With a few modifications in the list tags (for example changing the time format and removing small-tags) I got it exactly as I wanted it.

    When/if I find the time I will try to build my own widget.


    Posted 11 years ago #
  6. @Paul: Glad it works for you :) Have to thank Romik84 from Lesterchan's forums for the code snippet.

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.