WordPress.org

Forums

the loop (6 posts)

  1. Demetrius Pop
    Member
    Posted 2 years ago #

    I am just branching out into template pages and I am trying to get the loop to work in my custom theme. the meta data is showing up but not the content of my post.

    the code:

    <?php
    /*
    Template Name: blog
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="page-wrap" class="container_12 clearfix">
    
    <!-- The Loop -->
    
    <div class="grid_12">
       <? /*Begin Content area Query*/ ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute();
    ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php
    the_author() ?> --></small>
    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>
    <p class="postmetadata"><?php the_tags('Tags: ', ', ', ''); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    </div>
    <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php get_search_form(); ?>
    <?php endif; ?>
    
    </div>
    <!-- End Loop -->
    
    </div>
    
    </div>
    
    <?php get_footer(); ?>

    [how to post code: http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    you need to tell the loop what to show;

    http://codex.wordpress.org/Function_Reference/query_posts

  3. Demetrius Pop
    Member
    Posted 2 years ago #

    That works, thanks! :)

  4. Demetrius Pop
    Member
    Posted 1 year ago #

    I'm curious as to why you chose query_post as opposed to WP_Query?

  5. alchymyth
    Forum Moderator
    Posted 1 year ago #

    this does not matter much in a page template where 'query_posts()' is be the only query, and makes it easier to add pagination code.

    of course, the loop can be done with WP_Query().

    http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1

  6. Demetrius Pop
    Member
    Posted 1 year ago #

    I see. Cool, my question actually came from that thread. Small Internet!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags