最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

blog page showing only first post

programmeradmin2浏览0评论

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
  • I'm not sure, but I think index.php should not be used a Template... and surely you've checked /wp-admin/options-reading.php, right? – brasofilo Commented May 24, 2012 at 16:48
Add a comment  | 

3 Answers 3

Reset to default 1

It 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论