![](/img/trans.png)
[英]Wordpress Custom Post Loop - How to not print information from an Array that I don't need?
[英]post time don't change in loop - wordpress
我想要一個簡單的循環以獲取最新的五篇帖子,這些帖子僅包含帖子標題和我在下面編寫的循環中所用的時間,標題生成得很好,但是時間沒有變化。 因為它也會在循環時間內獲得其他帖子的第一篇帖子。 因此所有發布時間都是相同的。
請告知為什么時間不循環?
<?php $args = array( 'numberposts' => '5' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ ?> <li class="orbit-slide"> <div> <a href="<?php echo get_permalink($recent["ID"]); ?>" class="ticker-a"> <span><?php echo get_the_time($recent["g:ia"]); ?> </span> <?php echo $recent["post_title"]; ?> </a> </div> </li> <?php } wp_reset_query(); ?>
試試這個
echo get_the_time('', $recent["ID"]);
附帶說明。 這是一段效率更高的代碼,更容易輸出內容。
<?php
$args = array( 'posts_per_page' => '5', 'orderby' => 'most_recent' );
$recent_posts = new WP_Query( $args );
if ( $recent_posts->have_posts() ) : while ( $recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="orbit-slide">
<div>
<a href="<?php the_permalink(); ?>" class="ticker-a">
<span><?php the_time("g:i a"); ?> </span>
<?php the_title(); ?>
</a>
</div>
</li>
<?php
endwhile; endif;
wp_reset_query();
?>
感謝“阿倫”的回答1:
echo get_the_time('', $recent["ID"]);
感謝“ WizardCoder”的另一個循環解決方案:
<?php $args = array( 'posts_per_page' => '5', 'orderby' => 'most_recent' ); $recent_posts = new WP_Query( $args ); if ( $recent_posts->have_posts() ) : while ( $recent_posts->have_posts() ) : $recent_posts->the_post(); ?> <li class="orbit-slide"> <div> <a href="<?php the_permalink(); ?>" class="ticker-a"> <span><?php the_time("g:ia"); ?> </span> <?php the_title(); ?> </a> </div> </li> <?php endwhile; endif; wp_reset_query(); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.