Forums

using the loop in custom templates (3 posts)

  1. gatorbake
    Member
    Posted 3 years ago #

    Whenever I include the loop in one of my custom template pages, it fails. When I copy that exact same code (minus the template name code) and paste it into one of WP's standard pages (index.php, e.g.), it works fine and displays all posts.

    Is there a basic concept I'm not grasping here? Thanks.

  2. SimonJ
    Member
    Posted 3 years ago #

    Could you be more clear about what exactly you're doing when you try to include the loop?

    Let's say your custom template have an index.php

    What are you trying to include there ?

    Juste paste the loop code you're trying to use.

    Also, how exactly it fails? It shows no posts? You have an error message?

    S.

  3. gatorbake
    Member
    Posted 3 years ago #

    Thank for the reply SimonJ. When I started describing to you exactly how it failed, I realized what was happening.

    The basic concept I wasn't grasping is that apparently some of the predefined templates (like index.php) by default only grab "posts" via the loop.

    But when you create a custom template, you have to tell the loop to grab only posts. My page was grabbing other entries that were not posts and they showed up blank. To fix this I added the following line before my loop and it did the trick:

    query_posts("post_type=post");

Topic Closed

This topic has been closed to new replies.

About this Topic