[英]Wordpress: Get recent posts, exclude current post
我試圖獲取最近的帖子,僅在當前帖子的類別中,而排除當前帖子,但我無法使它正常工作:
$curr_cat = get_the_category();
$args = array( 'numberposts' => '10', 'post_status' => 'publish', 'category' => $curr_cat['0']->cat_ID, 'exclude' => $post->ID );
$recent_posts = wp_get_recent_posts( $args );
只是一遍又一遍地顯示當前帖子。
約翰,您可以嘗試以下類似的代碼,我不知道您的情況,但是在我的一個項目中對我有用
$args = array ('category__in' => $curr_cat['0']->cat_ID, 'posts_per_page' => 10, 'post__not_in' => array( $post->ID ) );
您的代碼很好,請確保您正在回顯您的帖子,例如:
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
}
如果執行上述操作,請確保已設置$post
,並且您位於類別存檔或單個發布文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.