Php Wordpress循环未返回超过1篇文章

Php Wordpress循环未返回超过1篇文章,php,wordpress,Php,Wordpress,我创建了一个按类别获取帖子的函数,我传递了一个参数来显示每页大约4篇帖子,但作为回报,我只获得1篇帖子 function get_recent_events($atts){ extract(shortcode_atts(array( 'posts' => 1, ), $atts)); query_posts(array('category_name' => 'Events', 'orderby' => 'date', 'order' => 'DESC'

我创建了一个按类别获取帖子的函数,我传递了一个参数来显示每页大约4篇帖子,但作为回报,我只获得1篇帖子

function get_recent_events($atts){
extract(shortcode_atts(array(
    'posts' => 1,
), $atts));

    query_posts(array('category_name' => 'Events', 'orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
  if (have_posts()) :
   while (have_posts()) : the_post();
    $output = '<a href="'.get_permalink().'">'.get_the_title().'</a><br />';
   endwhile;
   endif;

    wp_reset_query();
   return $output;
}
add_shortcode("recent_events", "get_recent_events");
函数获取最近的事件($atts){
提取(短码)附件(数组)(
“职位”=>1,
)美元(附件);;
查询帖子(数组('category\u name'=>'Events','orderby'=>'date','order'=>'DESC','showposts'=>$posts));
如果(have_posts()):
while(have_posts()):the_post();
$output='
'; 结束时; endif; wp_reset_query(); 返回$output; } 添加快捷码(“最近的事件”,“获取最近的事件”);
在第页上,它是通过使用带有参数[recent_events posts=“4”]的短代码调用的,它应该返回4篇文章,但我得到了1篇文章。有人能帮我解决这个问题吗

query_posts( 'posts_per_page=4' );

那么你在代码中使用的
'posts'=>1
呢?如果用户跳过并没有放置post参数,那么默认情况下它会设置为1,这样使用是可以的?永远不要使用我在wordpress codex中看到的
query\u posts
,这就是为什么如果你可以建议我,我会使用任何其他选项?我尝试过,但它不起作用当我试图在ul和li内部做同样的事情时,它带来了4篇帖子查询帖子('category\u name=Events&posts\u per\u page='。$posts);不工作,我不知道为什么会发生这种情况,但当我在ulli中包装输出时,它返回1,它确实有效?var dump从查询中得到结果,并查看返回了多少帖子