Support » Themes and Templates » Show Post Date on Recent Post widget

  • Resolved girrl

    (@girrl)


    Hi – I have the “Recent Post” widget to display links to my latest 3 blog entries. On top of this, how can I include the post dates next to these links?

    For example:

    Recent posts
    2/16/09 – Post one
    2/14/09 – Post two
    2/11/09 – Post three

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • This in sidebar.php or in a Widget created with Otto’s PHP Code widget:

    <?php
    $posts=get_posts('post_type=post&showposts=3');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php }
    }
    ?>
    Thread Starter girrl

    (@girrl)

    Thanks for this! I’m running into a problem though. I’m using Otto’s PHP code widget and pasted what you posted. It’s pulling the link for the page that I’m on…not my posts?

    If I have both “Recent posts” and the PHP code widget added, then the PHP code pulls from my recent posts correctly. But I don’t need/want both of these widgets.

    Any clue why it’s behaving like this?

    This is better:

    <?php
      $args=array(
        'showposts'=>3,
        'caller_get_posts'=>1
      );
     $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        endwhile;
      }
    ?>

    Thread Starter girrl

    (@girrl)

    Thank you so much!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show Post Date on Recent Post widget’ is closed to new replies.