【问题标题】:how to check how many posts of a category are in the first 10 posts of another category wordpress如何检查一个类别的帖子在另一个类别的前 10 个帖子中有多少个 wordpress
【发布时间】:2011-03-23 09:40:47
【问题描述】:

嗨,我有一个类别的最新消息,我在首页为那只猫输出了 10 个帖子

我也有类别 -环境 -政治 -运动

我在首页中为每个帖子输出 5 个帖子

我想检查我是否在最新新闻类别的前 10 个帖子中说 3 个来自政治的帖子 如何将政治猫中显示的帖子偏移该猫中的 3 个帖子,这样我就没有重复的内容头版。假设我在最新的新闻猫中有 5 个关于环境的帖子。好吧,我想将环境猫中的帖子抵消 5 等等。

希望有人可以帮助我:D 谢谢!

【问题讨论】:

    标签: wordpress theming


    【解决方案1】:

    例如,当您执行循环以在类别环境中显示帖子时,您可以存储 post->ID,然后将其用作最新循环中的“排除”参数..

    可能是这样的:

    <?php
    $exclude = array(); //this stores what should not be shown
    $args = array( 'numberposts' => 5, 'category' => [enviromentID] );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post);
        //your usual theming stuff here
        $exclude[] = $post->ID;
    endforeach;
    //same thing to the other categories
    $args = array( 'numberposts' => 5, 'category' => [latestID], 'exclude' => $exclude );
    //usual get posts loop here
    ?>
    

    【讨论】:

      猜你喜欢
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多