仅显示最新的自定义分类帖子

时间:2013-01-31 作者:kallekillen

我在头版上有一个自定义分类法设置为“启动”,我只想将这些分类法中最新的一个显示为启动,任何旧的分类法都将返回到循环并正常显示。

下面的代码atm显示飞溅罚款,但由于某种原因,在循环中再次复制飞溅:

$args = array(
    \'post_type\' => \'post\',
    \'posts_per_page\' => \'1\',
    \'order_by\' => \'date\',
    \'order\' => \'DESC\',
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'theme\',
            \'field\' => \'slug\',
            \'terms\' => array (\'text-image\', \'just-image\', \'just-text\')
        )
    )
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();
任何帮助都将不胜感激!

1 个回复
最合适的回答,由SO网友:Waseem Abu Senjer 整理而成

您应该将第一篇帖子的ID保存在一个变量中(例如$splash\\u post\\u ID),并在下一个循环中使用"post__not_in" => $splash_post_id , 在$args 大堆

$args = array(
    \'post_type\' => \'post\',
    \'posts_per_page\' => \'1\',
    \'order_by\' => \'date\',
    \'order\' => \'DESC\',
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'theme\',
            \'field\' => \'slug\',
            \'terms\' => array (\'text-image\', \'just-image\', \'just-text\')
        )
    )
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();
        $splash_post_id = get_the_ID();
          .......
          .......
    endwhile; 
endif;

$args = array(
     \'post__not_in\' => array($splash_post_id),
    \'post_type\' => \'post\',
    \'posts_per_page\' => \'10\',
    \'order_by\' => \'date\',
    \'order\' => \'DESC\',
);

$query = new WP_Query( $args );
if (have_posts()) :
    while( $query->have_posts() ) :
        $query->the_post();

          .......
          .......
    endwhile; 
endif;

结束

相关推荐

Landing Page - Redirect Loop?

为此,最近给出了此解决方案(感谢D先生)Wordpress redirect to landing page if not logged in 线<?php if($_SERVER[\'REQUEST_URI\'] != \'.../\' || $_SERVER[\'REQUEST_URI\'] != \'.../\'){ if(!is_user_logged_in()) { wp_redirect( \'http://www.mysite.com/landingp