• Hi,

    and sorry if my question is really stupid. I’m just trying to understand WP a bit more in depth and the process is not always the smoothest.

    I was creating a test page using the standard page.php template and I wanted to display:

    ? The regular page contents
    ? Underneath that, the posts as I would see them on the blog home page

    It was just a test, so bare with me if such a page wouldn’t be of much use on a real website.

    I thought I could copy and paste the Loop from the index.php into the page.php template and I would have solved my issue. Unfortunately this didn’t seem to output any posts at all. Using WP_Query, query_posts or get_posts would have done the trick instead.

    So my question is: why that Loop outputs all the posts on the home page (or index.php) and doesn’t output any post at all if used in the page template?

    Big thanks in advance ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • page.php is a reserved file for theme’s to display “pages”, “page templates” are files you can attach to WordPress “pages” so you can use that page url as a placeholder for whatever content your “page template” dictates it should output, be that post or page content… or whatever you want..

    page.php should not be used as a “page template”, WordPress won’t quite know if it’s a page template, or a theme archive file…

    Sorry if i can’t explain myself very well, but i can understand the confusion of pages/page templates/template files …. the naming system isn’t very clear, and can be somewhat confusing/misleading at times..

    Thread Starter svedish

    (@svedish)

    Hi t31os_,

    I have to admit I don’t understand the answer ?? So sorry! But maybe my question was not very clear either, so my apologies if this is the case.

    Ok, let’s say I create a template called various_contents.php and I assign it for the page with the title “Various Contents” in the CMS. In the template file, after the page contents I paste ALSO the index.php Loop to get a list of posts as well. It just doesn’t work. That Loop works perfectly in index.php, but won’t work in my newly created page template. Why?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why the idex.php Loop doesn’t work in a page template’ is closed to new replies.