I'm developing a wordpress theme that uses a static page as front page.

My wordpress is configured to use "Home" page as its front_page and "Blog" page to show the blog posts.

When i try to use the loop on my "Blog" page to list the posts i get a odd behavior, the loop runs fine but any method to get the post information returns an empty string.

Sample code:

if (have_posts()) {
  while(have_posts()) {
    $posts[$index] = array(
                'title' => get_the_title(),
                'permalink' => get_permalink(get_the_ID()),
                'content' => get_the_content(),
                'day' => get_the_date('j'),
                'month' => get_the_date('M')


If i have 5 posts that yould return me an array with 5 elements, all of them with empty strings as the values.

If i add query_posts('posts_per_page=5');. it works, but that shouldn't be needed.

What am i missing?

You can check the complete source code on github: https://github.com/albertein/coltsintheme

Thank you

UPDATE: Even if i avoid using a static page as front page (delete front-page.php and configure wp con Settings>Reaging) I'm getting the same results which seems weird to me, it seems I'm missing something.

  • Out of curiosity, is there any reason that you're adding another abstraction layer on top of the Template Hierarchy? Such unnecessary complexity often leads to these sorts of issues. Is there any reason you can't rename blog.php as home.php, and rename main.php as front-page.php, and just let WordPress handle the template laoding? (Also: your index.php won't work outside of the Front Page and the Blog Posts Index. Is this be design? Commented Mar 15, 2012 at 22:21
  • You are also using short-tags in your code <? should be <?php Commented Mar 15, 2012 at 23:43
  • @ChipBennett Even if i use strictly the template hierarchy (Moving blog to home and main to front-page) I'm getting the same behavior. index.php doesn't do anything else because i was waiting to solve this issue to avoid to construct a custom query on every page to make it work.
    – albertein
    Commented Mar 16, 2012 at 1:15
  • @ChipBennett i uploaded the code that follows wordpress template hierarchy to github, but still doesn't work.
    – albertein
    Commented Mar 16, 2012 at 1:45

1 Answer 1


Just before the snippet i posted i was doing something like $posts = array();, it seems that wordpress keeps the collection of the posts to be used on the loop in a variable of the same name, so i was meesing with the data, just changed $posts for $items and now works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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