ThemeShaper Forums » Thematic

[closed]

Multiple loops without repeating content

(6 posts)
  • Started 7 years ago by proto
  • Latest reply from proto
  • This topic is resolved
  1. proto
    Member

    Hello All,

    Well I'm nearly there! I've figured out how to incorporate the loop and use 960.gs within the loop and it validates as W3C Valid!

    The problem I'm having is that I am currently repeating posts in my loop. You'll see that "News 3" is repeated 3 times. See the homepage and you'll see what I mean here: https://www.universalonewebdesign.com/bespoke-design-eleven/

    I have three loops all calling posts from the same category 'latestnews'. I have tried using $counter to ask my loop to output after a certain count but couldn't get that to work. I also tried to store the post ID in an array and $do_not_duplicate but I kept getting a null value error message

    function pixelwoo_indexloop() {?>
    
    <div class="grid_6 alpha">
    <?php query_posts('category_name=welcome&posts_per_page=1');?>
    <?php while (have_posts()) : the_post();?>
    <?php thematic_postheader();?>
    <div class="entry-content">
    
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    
        </div><!-- entry-content -->
    
    <?php endwhile; ?>
    <?php rewind_posts(); ?>
    
    <div id="latestnewsheader" class="grid_6 alpha"><h1>Latest News</h1></div>
    <div class="grid_2 alpha">
    <?php $pixelwoo_latestnews_query = new WP_Query ('category_name=latestnews&posts_per_page=1');
    $counter = 1;
    while($pixelwoo_latestnews_query->have_posts()) : $pixelwoo_latestnews_query->the_post();
    $do_not_duplicate = $post->ID;?>
    <?php thematic_postheader();?>
    <div class="entry-content">
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    
        </div><!-- end of Entry Content -->
        </div><!-- end of Grid_2 alpha -->
    
        <?php endwhile; ?>
        <?php rewind_posts(); ?>
        <div class="grid_2">
        <?php $do_not_duplicate = array();?>
    <?php query_posts('category_name=latestnews&posts_per_page=1');
    $counter = 2;?>
    <?php while (have_posts()) : the_post();
    if ($counter == 2);?>
    <?php thematic_postheader();?>
    <div class="entry-content">
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    
      	 </div><!-- entry-content -->
         </div><!-- grid_2 alpha -->
    
        <?php endwhile; ?>
        <?php rewind_posts(); ?>
        <div class="grid_2 omega">
    <?php query_posts('category_name=latestnews&posts_per_page=1');
    $counter = 3;?>
    <?php while (have_posts()) : the_post();
    if ($counter == 3);?>
    <?php thematic_postheader();?>
    <div class="entry-content">
    
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    	</div><!-- entry-content -->
        </div><!-- grid_2 omega -->
        </div><!-- end of grid_6 alpha -->
    
        <?php endwhile; ?>
        <?php rewind_posts(); ?>
        <div class="grid_6 omega">
        <?php query_posts('category_name=ezanahomepic&posts_per_page=1');?>
    <?php while (have_posts()) : the_post();?>
    
    		<?php
          if (has_post_thumbnail()) {
            the_post_thumbnail('homepage_pic');
          } ?>
    
        </div><!-- entry-content -->
        </div><!-- homepage content -->
    
        <?php endwhile; ?>
      <?php ;}
      ?>

    I think it needs a tweak - any suggestions greatly appreciated! :)

    Posted 7 years ago #
  2. if all the queries are from the same cat what is the point of 3 queries? you can just trigger different markup w/ a counter variable. then you also won't need to exclude any posts or use any tricky offsets.

    see this for a good example.
    http://hardiannazief.com/12/create-custom-posts-layout-in-home-page-thematic-child-theme/

    it is a bit outdated as you no longer need to remove the action and then add it back, simply call your function childtheme_override_index_loop()

    Posted 7 years ago #
  3. proto
    Member

    Thanks Helga,

    The only reason I have three queries from the same category is that I'm using the 960.gs system which needs the first and last post in a column of three to have 'alpha' and 'omega' classes attached to each for positioning placement.

    I think what I need to work out is either, how to attach in one loop "alpha" to the first post and if is last loop add "omega" classes. Or stick with my current system and understand how to query the same category each time without getting the same post, any ideas from anyone greatly appreciated? :)

    Posted 7 years ago #
  4. middlesister
    Member

    The query parameter you are looking for is called offset. query_posts('category_name=ezanahomepic&posts_per_page=1&offset=2')

    But I agree with Helga, use your counter inside a single loop that fetches the three last posts and add the classes you need.

    <?php $counter++; ?>
     <div class="grid_2 <?php if ($counter == 1) { echo 'alpha'; } elseif ($counter == 3) { echo 'omega'; } ?>">
    Posted 7 years ago #
  5. proto
    Member

    Middlesister & Helga!

    Thanks so much, all hail the lovely helpers on here! In case anyone's wanting to do the same here's the loop to use with 360.gs!

    <?php query_posts('category_name=latestnews&posts_per_page=3');?>
    <?php while (have_posts()) : the_post();?>
    <?php $counter++; ?>
     <div class="grid_2 <?php if ($counter == 1) { echo 'alpha'; } elseif ($counter == 3) { echo 'omega'; } ?>">
    <?php thematic_postheader();?>
    <div class="entry-content">
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    
        </div><!-- end of Entry Content -->
        </div><!-- end of grid_alpha -->
    
        <?php endwhile; ?>

    *Obviously modify the counter to what grid system number and desired 'alpha' and 'omega' layout you'd like! :)

    Posted 7 years ago #
  6. proto
    Member

    Here's an added solution in case you want to assign a unique ID to each post, eg for specific post styling purposes, building on the brilliant work of Middlesister:

    <?php query_posts('category_name=latestnews&posts_per_page=3');?>
    <?php while (have_posts()) : the_post();?>
    <?php $counter++; ?>
     <div id="<?php if ($counter == 1) { echo'newsone" class="grid_2 alpha'; } elseif ($counter == 2) { echo 'newstwo" class="grid_2'; } elseif ($counter == 3) { echo 'newsthree" class="grid_2 omega'; } ?>">
    <?php thematic_postheader();?>
    <div class="entry-content">
    		<?php the_excerpt(); ?>
    
           <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
    
        </div><!-- end of Entry Content -->
        </div><!-- end of grid_alpha -->
        <?php endwhile; ?>

    *Obviously modify the counter to what grid system number and desired, ID values and 'alpha' and 'omega' post layouts that you'd like! :)

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.