从两个类别获取Wordpress帖子
问题描述:
我想在一个页面上显示来自两个类别的帖子(6 & 7)。它应该包括来自或类别的帖子以及匹配两者的帖子。不幸的是,我迄今为止只找到后者的解决方案,这就是为什么我现在要求你帮忙。这是我现在的代码:从两个类别获取Wordpress帖子
<div class="sponsoren_container_wrapper">
<?php $args = array ('posts_per_page' => -1, 'category' => 6);
$myposts = get_posts ($args);
foreach ($myposts as $post) : setup_postdata($post); ?>
<div class="gallery_image_container">
<a href="<?php
$content = get_the_content();
print $content;
?>" title="<?php the_title_attribute(); ?>">
<div class="gallery_image_thumb">
<?php the_post_thumbnail('thumbnail'); ?>
</div>
<div class="gallery_title">
<h2>
<?php the_title(); ?>
</h2>
</div>
</a>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
我该如何将类别ID“7”添加到该代码,以使所有工作都如上所述? 在此先感谢!
答
用逗号分隔的字符串:
$args = array ('posts_per_page' => -1, 'category' => '6,7');
答
$args = array ('posts_per_page' => -1, 'category' => '6,7');
$myposts = get_posts ($args);
林白痴,我试过了,但忘记把'围绕这...谢谢! – 2014-09-24 11:34:24
@NrGBar没问题。通常很容易忽视这些类型的东西 – Steve 2014-09-24 11:37:12