开发者

Display post date on previous/next link

开发者 https://www.devze.com 2023-04-07 14:37 出处:网络
I am about modifying the previous post (and next post) link in W开发者_Go百科ordpress. but I don\'t know how to show the date of the referred post.

I am about modifying the previous post (and next post) link in W开发者_Go百科ordpress. but I don't know how to show the date of the referred post.

I don't want an external plugin for this answer, but the code in functions.php will be great. (Note: I have read this. if this is the answer how to use it in very practical code?)

the final result should be like this:

< Previous (12 June 2011) | Current Post | (14 June 2011) Next >


The following code will output the link in the correct format from your single.php template:

    <?php $prev_post = get_previous_post(); ?>
    <a href="<?php echo get_page_link($prev_post->ID); ?>">&lt; (<?php echo mysql2date('d F Y', $prev_post->post_date, false) ?>) Previous</a>

I'll leave the next link as an exercise for you.


<?php echo get_the_date( 'd/m/Y' ); ?>

this will also show the date even posts within a day

0

精彩评论

暂无评论...
验证码 换一张
取 消