我正在做一系列循环,这些循环使用:
$myposts = get_posts("category=$category->id");
获取给定类别的所有帖子。但是我需要做类似的事情:
$myposts .= get_posts("category=$category->id");
所以 var $myposts 被添加到每个循环中。然后我需要按发布日期重新订购 $myposts 并重新循环。
知道如何实现这一目标吗?
我的完整代码是:
global $wpdb;
$categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description
from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent = '2' ORDER BY name ASC");
echo '<ul class="results">';
foreach($categories as $category) :
?>
<?php global $post;
$myposts = get_posts("category=$category->id");
foreach($myposts as $post) : setup_postdata($post);
?>
<li>
<a class="title" href="<?php the_permalink(); ?>"><span><?php the_title(); ?></span><br/><?php echo $category->name; ?></a>
<a class="image" href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post->ID, 'result') ?></a>
</li>
<?php endforeach; ?>
<?php endforeach;
echo '</ul>';
谢谢,
戴夫