admin管理员组文章数量:1416642
Live site.
My blog page is showing only the very first published page, and not the subsequent posts. I've noticed, too, that when viewing the page source, the blog page seems to be using single.php instead of index.php which is what I've set the template to be. Could this be the issue?
Below is the code in question:
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(); ?>
Live site.
My blog page is showing only the very first published page, and not the subsequent posts. I've noticed, too, that when viewing the page source, the blog page seems to be using single.php instead of index.php which is what I've set the template to be. Could this be the issue?
Below is the code in question:
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(); ?>
Share
Improve this question
asked May 24, 2012 at 16:38
user1255049user1255049
2413 gold badges14 silver badges37 bronze badges
1
|
3 Answers
Reset to default 1It appears that blog.php
is a custom static page template, yes?
If so, then the primary loop will display the post content of the static page to which it is applied.
If you want to create a custom page template that displays blog posts, you will need to create a secondary loop to query/output the required blog posts. I would say to follow the example in the Codex, but in this case: don't. That example currently uses query_posts()
, which is an incorrect implementation.
However: I suspect that what you're really trying to do here is to customize your blog posts index? If so, you shouldn't be using a custom page template at all, but rather, should be creating/modifying the appropriate template file, which, for the blog posts index, is (in order of priority):
home.php
index.php
You may want to delete sections of the php template that's not working to fix this. I discovered the template I copied from a blog as a starter template had errors in it from the start. Thus why the feed wasn't working.
Please verify that in Settings -> reading the number of posts -> Blog pages show at most the value is greater than 1.
本文标签: blog page showing only first post
版权声明:本文标题:blog page showing only first post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745254920a2650043.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/wp-admin/options-reading.php
, right? – brasofilo Commented May 24, 2012 at 16:48