Forums

Sticky posts in query_posts (2 posts)

  1. z1webb
    Member
    Posted 5 months ago #

    I'm having an issue. On the home page of my site, I use 4 query_post calls as I want an individual post to show up in each separate div. Example:

    <div class="colwide">
    
    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "1") { break; } else { ?>
    
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?><div class="entry">
    <?php the_content( '<span class="moretext">Continue Reading...</span>' ); ?>
    
    <?php $count1++; } ?>
    <?php endforeach; ?>
    </div>
    </div><!--End colwide-->
    
    </div><!--End mainposts-->
    
    <div id="recentposts" class="group">
    <div class="col1">
    
    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=1'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "1") { break; } else { ?>
    
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    <?php the_excerpt(); ?>
    
    <?php $count2++; } ?>
    <?php endforeach; ?>
    </div><!--End Col1-->
    
    <div class="col2">
    
    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=2'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count3 = 0; if ($count3 == "1") { break; } else { ?>
    
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    <?php the_excerpt(); ?>
    
    <?php $count3++; } ?>
    <?php endforeach; ?>
    </div><!--End Col2-->
    
    <div class="col3">
    <?php query_posts('showposts=1'); ?>
    <?php $posts = get_posts('numberposts=1&offset=3'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count4 = 0; if ($count4 == "1") { break; } else { ?>
    
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    <?php the_excerpt(); ?>
    
    <?php $count4++; } ?>
    <?php endforeach; ?>
    </div><!--End Col3-->			
    
    </div><!--End Recentposts-->

    I know that's a lot. In the first Query, I want just 1 sticky post to show up, OR the most recent post for a the category "Main." It doesn't matter which. Anyone have any thoughts on how to get only one post from the "main" category to work? Thanks in advance.

  2. z1webb
    Member
    Posted 5 months ago #

    In case my code isn't easy to decipher, I used this example to put the posts in multiple columns: http://perishablepress.com/press/2008/09/01/multiple-loops-and-multiple-columns-with-wordpress/

Reply

You must log in to post.

About this Topic