2017-05-04 57 views
1

我無法獲得要顯示的每個帖子的正確日期。即使我使用了「新WP_Query」,它也會顯示第一個條目的日期。顯示類別和Wordpress帖子的正確日期

我也無法獲得要顯示的類別類型。

<?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();?> 

回答

0

您已經

get_the_date('D M j',$recent), 

錯過 「ID」 請把它改爲

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

所以它會顯示每個帖子日期