• Having some trouble with a template im working on. For the homepage that displays no page data, I made a wordpress loop to loop out the latest 5 blog posts. However when including this function in the sidebar on another page that does display page content, the loop returns nothing.

    Ive tried using the wp_reset_query function and wp_reset_postdata but no luck.

    Any ideas?

    Page call;

    <?php the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
    <header class="entry-header">
    <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->
    
    <div class="entry-content">
    <?php the_content(); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'themename' ), 'after' => '</div>' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'themename' ), '<span class="edit-link">', '</span>' ); ?>
    </div><!-- .entry-content -->
    </article><!-- #post-<?php the_ID(); ?> -->

    Then the sidebar one;

    <?php wp_reset_query(); ?>
    <?php $latest = new WP_Query('showposts=5'); ?>
    <?php if (have_posts()) : ?>
    <?php query_posts("showposts=5"); // show five latest post only ?>
    <?php while (have_posts()) : the_post(); ?>
    <hr>
    <div class="blog-post">
    <h2><?php the_title(); ?></h2>
    <small>Posted: <?php the_time('G:H D m/y/ ') ?> <a href="<?php the_permalink(); ?>">Read More...</a></small>
    </div><!-- end blog post -->
    <?php endwhile; ?>
    <?php else : ?>
    <h2>No Posts to Display</h2>
    <hr>
    <?php endif; ?>

    Any help would be much appreciated 🙂

    [No bumping. If it’s that urgent, consider hiring someone.]

  • The topic ‘Using another wordpress loop on page’ is closed to new replies.