【问题标题】:Display category and correct date of Wordpress posts显示 Wordpress 帖子的类别和正确日期
【发布时间】:2017-10-02 06:22:28
【问题描述】:

我无法正确显示每个帖子的日期。即使我使用了“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();?>

【问题讨论】:

    标签: php wordpress categories getdate


    【解决方案1】:

    您在

    中错过了“ID”
    get_the_date('D M j',$recent), 
    

    请改成

    get_the_date('D M j',$recent["ID"]), 
    

    所以它会显示每个帖子的日期

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多