• Hello, guys.

    I want to achieve this effect on my Main Page:
    >> Current Post
    >> Current Aside
    >> About the Author
    >> Previous Posts

    Here is my code for the index page:

    <?php get_header(); ?>
    
    <div class="fresh">
    <img src="<?php bloginfo('template_directory'); ?>/images/fresh.png" alt=""/>
    </div>
    
    <!--1ST-A QUERY-->
    <?php
    $my_query = new WP_Query('showposts=1&amp;cat=8');
    
    while ($my_query->have_posts()) : $my_query->the_post();
    
    $do_not_duplicate = $post->ID; ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    
                  *current post here*
    
    <?php endwhile; ?>
    
    <div class="aside">
    <img src="<?php bloginfo('template_directory'); ?>/images/current_side.png" alt=""/>
    </div>
    
    <!--1ST-B QUERY-->
    <?php
    $my_query = new WP_Query('showposts=1&amp;cat=7');
    
    while ($my_query->have_posts()) : $my_query->the_post();
    
    $do_not_duplicate = $post->ID; ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    
                    *asides here*
    
    <?php endwhile; ?>
    
    <div class="author">
    <img src="<?php bloginfo('template_directory'); ?>/images/author.png" alt="" />
    *About the Author Here*
    </div>
    
    <div class="others">
    <img src="<?php bloginfo('template_directory'); ?>/images/previously.png" alt=""/>
    </div>
    
    <!--2ND QUERY-->
    <?php
    if ( have_posts() ) :
    while ( have_posts() ) : the_post();
    if (in_category( array('aside' , 'current-post') )) continue;
    elseif ( $post->ID == $do_not_duplicate ) continue;
    update_post_caches($posts);  ?>
    
    *previous posts here*         
    
    <?php endwhile; ?>

    As you can see, Asides don’t go into the Previous Post Sections anymore, but I have to manually set the Current Post with a specific category so it won’t get repeated in the Previous Post Loop, and deselect said category when it isn’t a current post anymore. Someone out there with a better and easier idea? Thanks. 🙂

The topic ‘Help with the Loop’ is closed to new replies.