tags:

views:

11

answers:

1

When viewing a post, I want to show the date of the previous post underneath the previous/next post links but $post is not available in previous_post_link().

How can I carry forward the post date from the previous post as well as get the date for the next link?

+1  A: 

Did a bit of searching on the web, but no result. Then I opened the file wp-include/link-tempalte.php.

On line 1327 you will find next_post_link which calls adjacent_post_link function. This function again calls get_adjacent_post function to retrieve previous post data.

Looking at the source, you should be able to do the following:

  $in_same_cat = false; 
  $excluded_categories = '';
  $previous = true;
  $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
  echo $post->post_date;

This is not tested, but I think it hould work.

Steven
Thanks for the tip. Alas, the post array returned by get_adjacent_post() doesn't have post_date but it does have the post ID (albeit in form http://example.com?p=21) so I can probably fudge it from here.
kidrobot
Back up! There is a post ID and date! It was being munged by the CSS.
kidrobot