开发者

how to check how many posts of a category are in the first 10 posts of another category wordpress

开发者 https://www.devze.com 2023-02-19 17:34 出处:网络
hi i have a category of latest news and i output 10 posts for that cat in the frontpage I also ha开发者_StackOverflow社区ve categories for

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

I also ha开发者_StackOverflow社区ve 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!


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
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号