0
我正在开发我的第一个WordPress主题,我有的第一个循环只输出1个项目:链接到主页(不是我试图在数组中传递的任何参数) 。get_posts只显示一个链接到主页
这里的PHP和HTML:
<div class="services_list">
<?php
$args = array(
'posts_per_page'=> 999,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'service',
'meta_key' => 'featured',
'meta_value' => '1'
);
// The Query
get_posts($args);
// The Loop
while (have_posts()) : the_post(); ?>
<div class="service_item">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="service_top_link">
<div class="service_image"><?php the_post_thumbnail(array(120,120)); ?></div>
</a>
<h3 class="service_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="service_excerpt"><?php the_excerpt(); ?></div>
<a href="<?php the_permalink(); ?>" title="Learn More" class="learn_more" role="button">Learn More</a>
</div><!-- .service_item -->
<?php endwhile;
// Reset Query
wp_reset_query();
?>
</div><!-- .services_list -->
我道歉,如果这个问题已经回答了,但我似乎无法找到它的任何东西。
对于二级循环,您应该使用['WP_Query'](https://codex.wordpress.org/Class_Reference/WP_Query)。有关何时使用什么的解释,请参阅http://wordpress.stackexchange.com/a/1755/38742。 – Peter