Title: Loop isnt working?
Last modified: August 20, 2016

---

# Loop isnt working?

 *  Resolved [NazarA](https://wordpress.org/support/users/nazara/)
 * (@nazara)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/)
 * Im completely confused and I dont know what to do!
 * I am developing a static page for a blog of mine. Here’s the html code
 *     ```
       <?php /* Template Name: Blog */ ?>
   
       <?php get_header(); ?>
       <div class="blog-container ">
       	<div class="mainblog">
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
   
               <div class="post">
                <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                  		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                           <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
        	    				<?php the_excerpt(); ?>
           	</div> <!--post-->
          <?php endwhile; endif; ?>
       </div> <!--mainblog-->
       <?php get_sidebar(); ?>
       </div> <!--blog-container-->
   
       <div><?php get_footer(); ?></div>
       ```
   
 * All i get is “Protected:blog” and “October 15, 2012 | 10:06 |” underneath it.
   I have made 2 quick posts which have dummy text and a featured image. (Which 
   is clickable in the sidebar)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145746)
 * is the ‘blog’ page set as ‘protected’ ?
 * for any blog posts to show, you need to add a query before the loop;
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 * for ideas, also see [http://codex.wordpress.org/Pages#A_Page_of_Posts](http://codex.wordpress.org/Pages#A_Page_of_Posts)
 *  Thread Starter [NazarA](https://wordpress.org/support/users/nazara/)
 * (@nazara)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145749)
 * For now the blog is protected.
 * It works (yay!) however now in my <title> all i get is ” | Blue Harlequin” (site
   is [http://www.blueharlequin.com](http://www.blueharlequin.com)), Im not getting
   this issue anywhere else!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145750)
 * what is the code for the meta title tag `<title>`, in header.php?
 *  Thread Starter [NazarA](https://wordpress.org/support/users/nazara/)
 * (@nazara)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145751)
 * `<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>`
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145752)
 * where did you add the query?
    can you post the full code of the latest version
   of the page template?
 * if using ‘query_posts()’ is interfering with the meta title, you might need to
   use a secondary loop for your blog posts;
 * example:
 *     ```
       <?php /* Template Name: Blog */ ?>
   
       <?php get_header(); ?>
       <div class="blog-container ">
       	<div class="mainblog">
          <?php $blogs = new WP_Query( array( 'post_type' => 'post', 'paged' => get_query_var('paged') ); ?>
          <?php if ($blogs->have_posts()) : while ($blogs->have_posts()) : $blogs->the_post(); ?>
   
               <div class="post">
                <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                  		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                           <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
        	    				<?php the_excerpt(); ?>
           	</div> <!--post-->
          <?php endwhile; endif; wp_reset_postdata(); ?>
       </div> <!--mainblog-->
       <?php get_sidebar(); ?>
       </div> <!--blog-container-->
   
       <div><?php get_footer(); ?></div>
       ```
   
 * [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 *  Thread Starter [NazarA](https://wordpress.org/support/users/nazara/)
 * (@nazara)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145753)
 *     ```
       <?php /* Template Name: Blog */ ?>
   
       <?php get_header(); ?>
           <h1>Blog</h1>
   
       <div class="blog-container ">
       	<div class="mainblog">
       <?php query_posts( 'posts_per_page=5' ); ?>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
   
               <div class="post">
                <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                  		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                           <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
        	    				<div class="the_excerpt"><?php the_excerpt(); ?></div>
           	</div> <!--post-->
          <?php endwhile; endif; ?>
       </div> <!--mainblog-->
       <?php get_sidebar(); ?>
       </div> <!--blog-container-->
   
       <div><?php get_footer(); ?></div>
       ```
   
 * This is the only issue im currently having! Other than that this’ll be all resolved
   🙂
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145754)
 * I can’t see any reason why the query would stop the page title from showing in
   the meta title tag (unless you are using a seo plugin?);
 * you could try to add ‘wp_reset_query();’ at the end of this line:
 *     ```
       <?php endwhile; endif; ?>
       ```
   
 * i.e.
 *     ```
       <?php endwhile; endif; wp_reset_query(); ?>
       ```
   
 *  Thread Starter [NazarA](https://wordpress.org/support/users/nazara/)
 * (@nazara)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145755)
 * Actually I am using an seo pack (all-in-one SEO to be exact)
 * Just tried your code and it works! Thank you! 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Loop isnt working?’ is closed to new replies.

 * 8 replies
 * 2 participants
 * Last reply from: [NazarA](https://wordpress.org/support/users/nazara/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/loop-isnt-working/#post-3145755)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
