我把这个循环放在一起,以显示所需猫的所有子帖子,但我没有从其中一个子猫那里得到任何帖子<不确定我是否在使用最佳方法来完成我正在尝试的事情。。
<?php
$posts = array();
$categories = get_categories(\'child_of=5\');
foreach($categories as $category) {
$args=array(
\'post_per_page\' => 5,
\'orderby\' => \'post_date\',
\'numberposts\' => 45,
\'category__in\' => array($category->term_id)
);
$posts = $posts + get_posts($args);
} // Close your foreach here
shuffle($posts);
if ($posts) {
foreach($posts as $post) {
setup_postdata($post);
?>
<div <?php post_class(\'boxy\');?>><div class="soc-label" ></div>
<?php
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), \'full\');
echo \'<a href="\' . $full_image_url[0] . \'" rel="lightbox" title="\' . the_title_attribute(\'echo=0\') . \'" >\';
the_post_thumbnail(\'thumbnail\');
echo \'</a>\';
}
?>
<?php the_content(\'\'); ?>
</div>
<?php }
}
?>
我在用同位素拼接的马赛克中使用这些结果,我正在对结果进行洗牌,这也是必须的。。如果有任何指导,我将不胜感激。过去几周,我一直在努力。
SO网友:StephenPerrett
我可以使用array\\u merge()使其正常工作。。这是代码。。仍然可能有一些代码错误,但它可以正常工作。
<?php
$posts = array();
$categories = get_categories(\'child_of=4\');
foreach($categories as $category) {
$args=array(
\'orderby\' => \'post_date\',
\'numberposts\' => 40,
\'category__in\' => array($category->term_id)
);
$posts = array_merge($posts,get_posts($args));
} // Close your foreach here
shuffle($posts);
if ($posts) {
foreach($posts as $post) {
setup_postdata($post);
?>
<div <?php post_class(\'boxy\');?>><div class="soc-label" ></div>
<?php
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), \'full\');
echo \'<a href="\' . $full_image_url[0] . \'" rel="lightbox" title="\' . the_title_attribute(\'echo=0\') . \'" >\';
the_post_thumbnail(\'thumbnail\');
echo \'</a>\';
}
?>
<?php the_content(\'\'); ?>
</div>
<?php }
}
?>