WordPress.org

Forums

[resolved] How to add the publishing time to recent posts (4 posts)

  1. gnurf
    Member
    Posted 5 years ago #

    Hi!
    I would like to use something similar to the Recent Posts widget, but I would like to show the time when the post was published after the listed title.

    Can anyone show me in the right direction, thanks!

    -Paul

  2. MichaelH
    Member
    Posted 5 years ago #

    <?php
    //display 10 posts with title and date
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 10,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> - <?php the_time('m.d.y') ?></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. gnurf
    Member
    Posted 5 years ago #

    thanks, it looks a bit similar to the solutions I got at the thematic forum (http://themeshaper.com/forums/topic/how-to-show-time-when-listing-recent-posts) which works with the php code widget.

  4. MichaelH
    Member
    Posted 5 years ago #

    which works with the php code widget.

    So does the code above...

Topic Closed

This topic has been closed to new replies.

About this Topic