如何检查一个类别的帖子有多少在另一个类别WordPress的前10个帖子中

发布于 2024-10-25 19:48:38 字数 250 浏览 1 评论 0原文

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

我也有以下类别 -环境 -政治 -体育

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

我想检查我是否在最新新闻类别的前 10 个帖子中包含 3 个来自政治的帖子,如何将政治猫中显示的帖子抵消 3 个帖子那只猫,所以我的首页上没有重复的内容。假设我在最新的新闻猫中有 5 个关于环境的帖子。好吧,我想将环境猫中的帖子抵消 5 等。

希望有人能帮助我:D 谢谢!

hi i have a category of latest news and i output 10 posts for that cat in the frontpage

I also have categories for
-enviroment
-politics
-sports

and i output 5 posts for each one in the frontpage

i want to check if i have lets say 3 posts from politics in the first 10 posts in the latest news category how to ofsset the posts shown in the politics cat by 3 posts in the that cat so i dont have duplicate content on the front page. lets say i had 5 posts for the enviroement in the latest news cat. well i would want to offset the posts in the enviroment cat by 5 and so on.

Hope someone can help me out :D THANKS!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情癖 2024-11-01 19:48:38

例如,当您执行循环以在类别环境中显示帖子时,您可以存储 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
?>

When you do the loop to show posts in category enviroment, for example, you could store the post->ID, then you use it as "exclude" parameter in your latest loop..

It could be something like this:

<?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
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文