我正在创建一个wordpress页面来显示特定类别的帖子列表。我通过以下方式使用函数query_posts:
$posts = query_posts(array('category_name'=>'formazione'));我的问题是,即使没有循环,该函数也会显示post内容,并将输出重定向到$posts变量。
如何避免显示帖子内容?
发布于 2015-07-28 19:13:47
不要一开始就使用变量$posts,就像问题的注释中所说的那样。
理想情况下,可以考虑使用get_posts() https://codex.wordpress.org/Template_Tags/get_posts来获取帖子。在该页面的底部有关于如何使用它的示例。
$args = array( 'category_name' => 'formazione' );
$myposts = get_posts($args);等等。查看页面,了解如何处理返回的$myposts数据。
https://stackoverflow.com/questions/31674296
复制相似问题