Show the_date with link

时间:2015-09-06 作者:Horby

我尝试显示带有相同日期链接的\\u日期!

 <?php the_date(\'l j F Y\', \'<tr>
 <th colspan="3"><a href="<?php the_date(\'Y/m/d\'); ?>" rel="bookmark">\', \'</th>
 </tr>\'); ?>

2 个回复
SO网友:Erfo

尝试以下操作:

<?php 
$archive_year  = get_the_time(\'Y\'); 
$archive_month = get_the_time(\'m\'); 
$archive_day   = get_the_time(\'d\'); 
?>
<a href="<?php echo get_day_link( $archive_year, $archive_month, $archive_day); ?>"><?php the_date(\'Y/m/d\'); ?></a>
HTML结果:

<a href="http://example.com/2015/09/07">2015/09/07</a>

SO网友:Erfo

<?php 
$archive_year  = get_the_time(\'Y\'); 
$archive_month = get_the_time(\'m\'); 
$archive_day   = get_the_time(\'d\'); 
?>
<a href="<?php echo get_day_link( $archive_year, $archive_month, $archive_day); ?>"><?php the_date(\'Y/m/d\'); ?></a>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
HTML结果:

<a href="http://example.com/2015/09/07">2015/09/07</a>
<a href="http://example.com/title-post">Title Post</a>
例如,如果要显示最新帖子:

global $post;
$post_args = array(
    \'posts_per_page\' => 5
);
$the_query = new WP_Query( $post_args );

if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        $archive_year  = get_the_time(\'Y\'); 
        $archive_month = get_the_time(\'m\'); 
        $archive_day   = get_the_time(\'d\'); 
    ?>
        <a href="<?php echo get_day_link( $archive_year, $archive_month, $archive_day); ?>"><?php the_date(\'Y/m/d\'); ?></a>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    }
wp_reset_query();
}

相关推荐