WordPress.org

Ready to get started?Download WordPress

Forums

Displaying "the loop" within a Page (6 posts)

  1. swreinha
    Member
    Posted 9 years ago #

    Hello,

    I am attempting to use "The loop" functionality to display posts on a dynamic Page in wordpress.
    I am using WordPress 1.5 and have read the codex thoroughly as well as many topics here on the support forum but have been unsuccessful in implementing what I have in mind.

    In my attempts, I have utilized the example template on the codex in creating a page which uses the loop. The page displayed only the title of the page I had just created instead of the expected posts.

    My wordpress setup is as follows:
    - WordPress 1.5 installation, root directory
    - using home.php as main home page (no posts)
    - wish to create 'blog' page using a 'loop' template to display posts
    - using permalinks structure /blog/%year%/%monthnum%/%day%/%postname%/

    Any thoughts on this issue or suggestions on an alternate setup would be greatly appreciated.

    Thank you,
    Steven

  2. Actually, you're lucky that you got any PHP to render in the first place. You'll have better luck if you activate one of these plugins:

    http://www.navidazimi.com/projects/wp-exec

    or

    http://mark.scottishclimbs.com/archives/2004/07/02/running-php-in-wordpress-posts/

    More info: http://wordpress.org/support/topic.php?id=23932

  3. swreinha
    Member
    Posted 9 years ago #

    Hi macmanx,

    Thanks for your reply.

    That plugin will run php code inserted into a Page is that correct?
    Now as I understand, the template file will execute the php code. The Page (which is generated from that template) doesn't have any code in it, in fact, it is completely blank. All the display elements should be pulled from the template file itself.
    The issue is, the code in the template file used to display is infamous 'Loop' isn't working as it should, despite what the wordpress codex is telling me. I am wondering why that is. Or have I missed something fundamental about 'Pages' in WordPress 1.5 ?

  4. Kafkaesqui

    Posted 9 years ago #

    Note that a standard use of The Loop on a Page template runs much like it would on a single.php template: it only outputs the contents of that individual Page. To get more out of it you're going to need to implement the query_posts() function to call up the posts you want to display. For example, just before The Loop occurs on a template I've set up for my "archives" Page, I have this:

    <?php query_posts("orderby=post_date&order=DESC&showposts=20"); ?>

    This displays the last 20 posts, ordered by post date (in descending order).

  5. swreinha
    Member
    Posted 9 years ago #

    Thank you Kafkaesqui,

    That clears up a lot. So the page itself was being treated as a post. That is why only the page name was being displayed. In order to display other posts the database has to be queried.

    That solution worked for me perfectly. I very much appreciate both of your help.

    Thank you,
    Steven

  6. -

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.