• Okay, so I’d like to have two loops on my site. The first loop is on a blog page and the second loop is on the home page. The first loop is set to a blank Page called “Blog”. This is where my regular index of posts is. To do this I had to go to Reading settings and set the front page as a static page and point the Posts Page to my blank “Blog” page. So far so good, the posts show up on the Blog page. Now I took that loop and copy pasted it to the Home Page (which is what Front Page is directed to), taking out the post snippet so it just shows the title and date. The only problem is that since the Posts Page is being directed at the Blog Page, the posts only show up there and refuse to show up on the Home Page as well.

    I’m using the have_posts() conditional for both loops.

    Any suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Your Home page needs to have a call to query_posts() before the have_posts() test. At a minimum, it could be something like this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'paged' => $paged,
    );
    query_posts($args);
    if (have_posts()) {
    // rest of loop here
    Thread Starter BenMoseley

    (@benmoseley)

    This is what I have. It’s outputting actual php into the page now.

    <ul class='latest'>
    	<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'paged' => $paged,
    );
    query_posts($args);
    if (have_posts()) {
    
    if(have_posts()) : ?>
    			<?php while(have_posts()) : the_post() ?> 
    
    		<li><h4><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    		<span><?php the_time('F jS') ?></span>
    		</li>
    	<?php endwhile; ?>
    </ul>
    	<?php else :?>
    			<h2>Faith has no recent posts.</h2>
    		<?php endif; ?>
    	<p class='latest'><a href="blog">Browse more journal entries from Faith</a></p>

    Change the first part to this by taking out the extra if (have_posts()) line just after the query_posts() line:

    <ul class='latest'>
       <?php
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args = array(
          'paged' => $paged,
       );
       query_posts($args);
       if(have_posts()) : ?>
          <?php while(have_posts()) : the_post() ?> 
    
             <li><h4><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
                <span><?php the_time('F jS') ?></span>
             </li>
          <?php endwhile; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add a loop on two different pages’ is closed to new replies.