Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress WP_查询返回除发布内容以外的所有内容_Wordpress_Loops - Fatal编程技术网

Wordpress WP_查询返回除发布内容以外的所有内容

Wordpress WP_查询返回除发布内容以外的所有内容,wordpress,loops,Wordpress,Loops,我只是想在模板页面上显示第7类帖子的内容。我在模板页面上使用了以下内容: <?php $custom_query = new WP_Query('cat=7'); while($custom_query->have_posts()) : $custom_query->the_post(); echo get_the_title(); endwhile; wp_reset_postdata(); ?> 此代码仅返回类别7中的帖子标题,而不输出实际帖子内容

我只是想在模板页面上显示第7类帖子的内容。我在模板页面上使用了以下内容:

<?php 
  $custom_query = new WP_Query('cat=7');
  while($custom_query->have_posts()) : $custom_query->the_post();
echo get_the_title();
endwhile;
  wp_reset_postdata();
?>


此代码仅返回类别7中的帖子标题,而不输出实际帖子内容。我添加了get_the_title()行,只是为了查看查询是否确实在查询帖子。由于它按预期返回了标题,因此我假设它正在按预期查询帖子。但为什么没有内容??这是一个本地站点,因此我无法提供链接。上述代码中是否有明显缺失的内容?

您肯定需要添加
内容()以使帖子内容可见?

UGH。。。我知道这很简单。多谢!如果你只是把标题放在;而不是获取标题();,您不需要echo命令。获取标题();是当您想在代码中使用它时,_title();就是当你把它放在页面上的时候。内容、元数据等也是如此。此外,正如注释所示,如果评论者正确回答了您的问题,通常会将答案标记为正确(在答案的左侧打勾:)