您发布的代码根本不查询任何内容。为此,请使用WP_Query
对象请不要使用query_posts
, 尤其是二次回路。抄本:
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
endwhile;
您只需提供
$args
. 在你的情况下
array(\'posts_per_page\'=>3)
$args = array(\'posts_per_page\' => 3); // or however many you want
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
endwhile;