[英]Display category and correct date of Wordpress posts
我无法确定要显示的每个帖子的正确日期。 即使我使用了“new WP_Query”,它也会显示第一个条目的日期。
我也无法获得要显示的类别类型。
<?php
$blogloop = new WP_Query( array( 'numberposts' => '3' ) );
$recent_posts = wp_get_recent_posts( $blogloop );
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
foreach( $recent_posts as $recent ){
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo ' <div class="col-md-4 col-xs-12">
<a href="' . get_permalink($recent["ID"]) . '"><div class="blog-item"><div class="home-blog-img" style="background-image: url('.get_the_post_thumbnail_url($recent["ID"]).')"></div><div class="home-blog-content"><h3>'. $recent["post_title"] .'</h3><p>'. get_the_date('D M j',$recent) .'</p><span> | </span><p>'. sprintf( esc_html__( 'Category: %s', 'textdomain' ), $category_link ) .'</p></div></div></a></div> ';
}
?>
<?php wp_reset_query();?>
你错过了“身份证”
get_the_date('D M j',$recent),
请改成它
get_the_date('D M j',$recent["ID"]),
所以它会显示每个帖子的日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.