【发布时间】:2018-01-05 07:18:56
【问题描述】:
好的,我正在尝试运行 wordpress 帖子循环以使用 the_title() 和 the_content() 打印帖子标题和内容。但它没有打印出页面上的帖子?
有什么想法吗?
index.php
<div class="blog-container">
<!-- The POST LOOP -->
<?php
if(have_posts()) :
while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else :
echo '<p>No content found</p>';
endif;
?>
</div>
编辑好的,我只打印内容而不是帖子标题,这是一张图片:http://imgur.com/a/DiBqG。
编辑 2 内部 wordpress 管理帖子应如下所示:http://imgur.com/a/1DQAp
【问题讨论】:
-
如果在开始循环之前添加
global $wp_query; var_dump($wp_query); die;会发生什么。查询对象中是否列出了任何帖子? -
我觉得不错。也许您在一个没有帖子的页面上?您可以启用查询日志。
-
你可能想也可能不想使用
<pre>标签来更好地格式化输出。 -
好的,我只打印内容而不是帖子标题,这是一张图片:imgur.com/a/DiBqG
-
请分享您的网站链接
标签: php html wordpress css loops