【问题标题】:Wordpress: Get recent posts, exclude current postWordpress:获取最近的帖子,排除当前的帖子
【发布时间】:2013-11-09 13:42:22
【问题描述】:

我正在尝试获取最近的帖子,仅在当前帖子的类别中,同时排除当前帖子,但我无法使其工作:

$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 );

它只是一遍又一遍地显示当前帖子。

【问题讨论】:

  • 您的代码一切正常。你想怎么输出这个?

标签: php wordpress


【解决方案1】:

约翰,你可以试试下面的代码,我不知道你的情况,但它适用于我的一个项目

$args = array ('category__in' =>  $curr_cat['0']->cat_ID, 'posts_per_page' => 10, 'post__not_in' => array( $post->ID ) );

【讨论】:

    【解决方案2】:

    您的代码没问题,请确保您正在回复您的帖子,例如:

    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 并且您位于类别存档或单个帖子文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 2017-08-25
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多