admin管理员组文章数量:1391987
What's wrong in the code below ? Even after comparing it with pre-existing codes, I don't get the mistake:
$args = array('cat' => 367);
$arr_posts = new WP_Query($args);
if ($arr_posts->have_posts()) {
while ($arr_posts->have_posts()) {
$arr_posts->the_post();
}
} else {
echo "No posts found";
}
Result: Nothing appears, not even the "No posts found" message. But the page is displayed without any error message.
What's wrong in the code below ? Even after comparing it with pre-existing codes, I don't get the mistake:
$args = array('cat' => 367);
$arr_posts = new WP_Query($args);
if ($arr_posts->have_posts()) {
while ($arr_posts->have_posts()) {
$arr_posts->the_post();
}
} else {
echo "No posts found";
}
Result: Nothing appears, not even the "No posts found" message. But the page is displayed without any error message.
Share Improve this question asked Mar 8, 2020 at 22:33 JoeJoe 351 silver badge9 bronze badges 3 |1 Answer
Reset to default 1There's nothing in your code that outputs anything for each post. That's not what $arr_posts->the_post();
does. You need to use template tags like the_title()
and the_content()
to output those fields:
while ($arr_posts->have_posts()) {
$arr_posts->the_post();
the_title( '<h2>', '</h2>' );
the_content();
}
本文标签: phpDisplay post of specific category on page
版权声明:本文标题:php - Display post of specific category on page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744685971a2619699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_title()
into the loop. – Michael Commented Mar 8, 2020 at 22:58