这是正确实现父ul和子ul中的wordpress循环吗? 我有一些问题,因为父输出正确,但孩子没有。该名儿童的职称名称仅在父母一个名单中输出。
<ul class="multi-category">
<?php query_posts(array('post_type' => array('post'),'posts_per_page' => 3)); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<li>
<h3>
<a href="<?php the_permalink(); ?>">Food</a></h3>
<div class="multi-category-image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Fun creations with potatoes and rice">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail(420,470);
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
<?php } ?></a>
<div class="multi-category-text">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div><!--multi-category-text-->
</div><!--multi-category-image-->
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
<div class="multi-category-headlines">
<ul class="multi-category-headlines">
<?php query_posts(array('post_type' => array('post'),'posts_per_page' => 4)); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
</ul>
</div><!--multi-category-headlines-->
</li>
</ul>
答案 0 :(得分:0)
我认为你不应该使用query_posts
。 It messes up the wordpress loop.
改为使用Wp_query:
( ..parent loop .. ..the_title()..etc )
$args = array(
'numberposts' => 10,
'post_type' => 'my-post-type',
'post_status' => 'publish' );
$myloop = new WP_Query($args); //<-- do the query for my subloop
// Now use the $myloop to form the subloop
// In loop you can forget $myloop and juse just the wordpress template tags like in
// the main loop.
if ( $myloop->have_posts() ): while ( $myloop->have_posts() ) : $myloop->the_post();
the_title(); // <-- wordpress now knows it's for the $myloop loop
endwhile;
endif;
wp_reset_postdata(); //<<-- return to the main loop. don't forget it
( ..parent loop .. )
希望这会有所帮助。见编码。这很简单。