现场直播。
我的博客页面只显示第一次发布的页面,而不是随后发布的文章。我还注意到,当查看页面源时,博客页面似乎使用的是single.php而不是index.php,而这正是我设置的模板。这会是问题吗?
以下是有关的守则:
index.php
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="container">
<div id="blog">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="headline">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div><!-- end headline -->
<div id="post-meta">
<p>written by <?php the_author(); ?> on <?php the_date(); ?></p>
</div><!-- end post-meta -->
<div id="post">
<?php the_content('read more...'); ?>
</div><!-- end post -->
<?php endwhile; ?>
<?php else : ?>
<p>I'm not sure what you're looking for.</p>
<?php endif; ?>
</div><!-- end blog -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>发布于 2012-05-24 16:49:24
看来blog.php是自定义静态页面模板,是吗?
如果是这样,那么主循环将显示应用它的静态页面的post内容。
如果要创建显示博客帖子的自定义页面模板,则需要创建一个辅助循环来查询/输出所需的博客帖子。我会说遵循法典中的例子,但在本例中:不要。该示例目前使用query_posts(),这是一个不正确的实现。
然而:我怀疑你在这里真正想做的是定制你的博客帖子索引?如果是这样的话,您根本不应该使用自定义页面模板,而是应该使用创建/修改适当的模板文件,对于博客帖子索引来说,它是(按优先级排列):
home.phpindex.php发布于 2018-11-26 13:57:36
您可能希望删除php模板中无法修复此问题的部分。我发现了我从博客复制的模板,因为初学者模板从一开始就有错误。这就是为什么饲料不能工作的原因。
发布于 2019-08-09 18:17:21
请验证在“设置->”中,阅读->博客页面的文章数量最多显示的值大于1。
https://wordpress.stackexchange.com/questions/53180
复制相似问题