我想看看是否可以使用循环中的args在主页上显示所有顶级帖子类别中的“最新”帖子?看见http://blog.reneerouleau.com/dev/ 例如,我当前设置的内容。我正在运行shoestrap wp。
<?php
wp_reset_query();
$cats = get_categories(\'\');
foreach ($cats as $cat) :
if($cat->category_parent) continue; //this line avoids to show posts of sub categories
$args = array(
\'posts_per_page\' => 1,
\'category_name\' => $cat->slug,);
query_posts($args); // reset to original
?>
UPDATE 仍然不能使用下面更新的代码-我想我可能需要在上面的新代码中添加post循环-有什么想法吗?
<?php get_template_part( \'templates/page\', \'header\' ); ?>
<div id="blogContainer">
<?php do_action( \'shoestrap_index_begin\' ); ?>
<?php if ( !have_posts() ) : ?>
<div class="alert">
<?php _e( \'Sorry, no results were found.\', \'shoestrap\' ); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<?php
$cats = get_categories(\'parent=0\');
foreach ($cats as $cat) :
$args = array(
\'posts_per_page\' => 1,
\'category__in\' => array( $cat->term_id ) );
$top_cat_query = new WP_Query($args);
if( $top_cat_query->have_posts() ) while( $top_cat_query->have_posts() ) :
$top_cat_query->the_post();
//output
endwhile; wp_reset_postdata();
//..etc..
endforeach;
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php do_action( \'shoestrap_in_loop_start_action\' ); ?>
<?php get_template_part( \'templates/content\', get_post_format() ); ?>
<?php endwhile; ?>
</div>
<div id="temp">
</div>
<div>
<?php if ( $wp_query -> max_num_pages > 1 ) : ?>
<nav class="post-nav">
<ul class="pager">
<li class="previous"><?php next_posts_link( __( \'← Older posts\', \'shoestrap\' ) ); ?></li>
<li class="next"><?php previous_posts_link( __( \'Newer posts →\', \'shoestrap\' ) ); ?></li>
</ul>
</nav>
<?php endif; ?>
</div>
<?php do_action( \'shoestrap_index_end\' ); ?>\'