WordPress.org

Forums

Trouble Display Loop on Custom Templage Page (3 posts)

  1. Preeminent
    Member
    Posted 3 years ago #

    Hello all,
    I'm having issues getting blog posts to show on a custom template page.

    I'm using the following:

    <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
    
          <div id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></ a></div>
    
            Posted in <?php the_category(', ') ?> by <?php the_author() ?> on <?php the_time('F jS, Y') ?> | <?php edit_post_link('Edit', '', ' | '); ?><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>  
    
              <div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>
              <?php endwhile; ?>
         <?php posts_nav_link(); ?>
         <?php else : ?> <h2>Not Found</h2>
    <p><?php _e("Sorry, no posts or pages could be found. Why not search for what you were trying to find?"); ?></p> <?php get_search_form(); ?>
    
    <?php endif; ?>

    I've tried a few different ways and nothing has worked for me.
    I just don't see what is wrong?

    I'm getting the following to output:
    "Blog
    Posted in by admin on September 18th, 2011 | Edit | No Comments"

    So basically, it's outputting the title of the page: "BLOG" and it's giving me who posted and when, but the odd thing is that the meta data isn't for any real blog post. I have two test blog posts published to test with this, and neither of them will show, just this weird metadata that's not even for either one of the blog posts.

    Can anyone help me? Thank You!

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    you need to add a query before the first line to tell the loop what to show; (otherwise it will just try to show the content and data fo rthe page)

    if you want to show the recent posts, add for example:

    <?php query_posts('post_type=post&posts_per_page=5&paged='.get_query_var('paged')); ?>

    (untested)

    (for the full list of possible arguments see http://codex.wordpress.org/Class_Reference/WP_Query#Parameters)

    and after the last line add:

    <?php wp_reset_query(); ?>

  3. Preeminent
    Member
    Posted 3 years ago #

    That worked! Thank You Very Much! I swear I just read through pages of the codex, PLUS a wordpress e-book, and I did not see anything about that anywhere. Ugh. Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic