Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working with a WordPress CMS website that was set up without a blog. I want the site to continue to function as it has, with mostly static pages, including the home page. I want a page called "Blog" to function as a blog.

Now I've been asked to add a blog, and what I expected would be extremely easy isn't turning out that way.

This is what I've tried:

  1. Added a page called "Blog" and published it.
  2. Under Settings >> Reading, set the Posts page to Blog. (A Static Page is selected, with Front Page set to "Home".)
  3. Added Blog to the main navigation in the Theme Options.
  4. Created 2 posts.

When I view the Blog page, two messages appear instead of the two blog posts:

Please go to Admin Panel > Settings > Reading and setup "Front page displays" option

Another detail that may be relevant is there are only 2 page templates: Default Template and Archives. If I select Archives as the template for Blog, I get an archive menu that links to the 2 posts I set up.

Should I have a Blog Template as well? How can I add one? What else should I look at?

share|improve this question
    
Did you: `Please go to Admin Panel > Settings > Reading and setup "Front page displays" option'? –  Stephen Nov 17 '12 at 3:37
1  
It will be hard to answer your question as we don't know how the theme that you are using is set up. Some themes offer a specific blog template, but it appears that the one that you are using doesn't. Now, once you set the template for your Blog page to Archive, you said you are getting 2 posts linked. Aren't these you blog posts? What posts are these? –  Mateusz Hajdziony Nov 17 '12 at 3:38
    
@pogoking: yes, the posts appear instead of the message when I set the template to archive. However, they appear under an archive menu structure, rather than as current posts. I believe we have a modified twenty eleven theme. –  Head of Catering Nov 17 '12 at 3:42
    
@Stephen: I tried to, but not sure I did it correctly -- see step 2 in my question. –  Head of Catering Nov 17 '12 at 3:42
add comment

2 Answers

So, everything seems to be set up correctly. The setting in your step 2 is everything that needs to be done. I won't be able to help you without seeing how the theme's template files are structured.

The way it usually works when you apply the setting in your step 2 is that WordPress looks for a template called front-page.php, if it doesn't exist then WordPress uses index.php.

Now, one of these templates must use the regular post loop, that is

if ( have_posts() ) :
while ( have_posts() ) :
the_post()

I assume that this loop is not present in your index.php or front-page.php files, and this is why your posts are not showing.

share|improve this answer
    
Actually, static page as front page falls back from front-page.php, to page.php (including custom page templates, before page.php), and then to index.php. –  Chip Bennett Nov 17 '12 at 4:49
    
+1 - your answer helped, but didn't solve my problem. –  Head of Catering Nov 19 '12 at 2:27
add comment
up vote 0 down vote accepted

Pogoking's answer helped point me in the right direction, but didn't solve the problem. This is what I ended up doing.

I created a new template within the customized theme we are using and edited the blog page to use the new template.

.../html/wp-content/themes/[custom theme name]/blogposts.php

I added the loop to the new template along with a query with a few parameters. I'm sure I'll modify the template substantially, but it works for now. All blog posts are displayed as I want them to.

Here is my code:

<?php
/*
Template Name: Blog Template
*/
?>
<?php get_header(); ?>

    <?php  
    $args = array(
                   'post_type' => 'post',
                   'posts_per_page' => 10,
                   'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                   );

    query_posts($args);  
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>  
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
    <h2><a href="<?php the_permalink(); ?>"
        title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
     </h2>
    <small>By <?php the_author_posts_link() ?>  | Published: <?php the_date() ?></small>
    <div class="thecontent">
    <br />
    <?php the_content(); ?>
    </div>
    <br />
    <hr>
    <br />
    <?php endwhile; else: ?>  
    // Our Blog will be online soon. Stay tuned... //
    <?php endif; ?> 
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
    </div>
    <?php
wp_reset_query();  // Restore global post data
?>
    <?php get_sidebar(); ?>

<?php get_footer(); ?>
share|improve this answer
    
If you select the blog page as the page for posts under settings, you shouldn't have to then call query_posts to display the blog posts, you should just be able to run the loop on the default query and it will output the number of posts configured in your reading settings. If adding the call to query_posts is necessary, something is amiss elsewhere in your theme. It's important to note that the use of query_posts in the template overwrites the default query, so what you're doing here is running two queries for each page load, which is a waste of resources. –  Milo Nov 19 '12 at 3:47
    
@Milo, something is definitely amiss, which is what caused the behavior I was trying to untangle in my question. I think whoever modified the theme for our site botched something, but I haven't figured out what yet. –  Head of Catering Nov 19 '12 at 4:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.