wordpress查询在functions.php中不起作用

wordpress查询在functions.php中不起作用,php,wordpress,Php,Wordpress,functions.php文件中的以下代码不返回任何内容,甚至不返回hi: ... <?php wp_reset_postdata(); $qr = new WP_Query(); while( $qr -> have_posts() ) { echo "hi"; $qr -> the_post(); echo comments_number('0', '1', '%'); } ?> 。。。 试试这个: $qr = new WP_Query(' '); whi

functions.php文件中的以下代码不返回任何内容,甚至不返回hi:

...
<?php 
wp_reset_postdata(); 
$qr = new WP_Query(); 
while( $qr -> have_posts() ) {
echo "hi"; $qr -> the_post(); 
echo comments_number('0', '1', '%');
} ?>
。。。
试试这个:

$qr = new WP_Query(' '); 
while( $qr->have_posts() ) {
echo "hi"; $qr->the_post(); 
comments_number('0', '1', '%');
}
wp_reset_postdata(); 

首先,你必须这样做。另外,
comments\u number
已经回显了结果,因此您不需要在那里回显该结果。

您确定它正在运行吗?如果将
echo
移动到while循环之外,是否会得到任何输出?wwhy将
wp\u reset\u postdata
移动到末尾?@FranciscoCorralesMorales,“使用此函数在第1段中的“从”恢复主查询循环之后主查询循环的全局$post变量。”