簡體   English   中英

get_the_date()不重復日期

[英]get_the_date() not repeating date

<div class="page-content">

<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<br />
<?php
the_content();
echo get_the_date('l,d');
endwhile;
endif;
?>

</div>

本示例不重復每個帖子的日期。 我在頁面模板(即services-template.php)中使用代碼,並且我已經閱讀了注釋,指出get_the_date()將重復每個帖子的日期。 有人可以幫我弄清楚我在做什么錯嗎?

我無法使原始代碼正常工作,我不知道Wordpress的所有內部工作原理,但我的猜測是,變量所保存的帖子數據(很可能是$ post)是空的。 以下代碼完成了我想要做的事情。 同樣,我在自定義頁面上使用此代碼。 服務-的template.php。

$args = array( 'category' => '4' );

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li><h2>' . get_the_title() . '</h2></li>';
        echo '<li>' . get_the_date() . '</li>';
        echo '<li>' . get_the_excerpt() . '</li>';
        the_tags();
        echo '<br /><br />';

    }
    echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

;
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM