WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple Complicated Loops (4 posts)

  1. kennethwatt
    Member
    Posted 5 years ago #

    Hi guys

    I have a div section at the top of a page, and then another one below, and I want the top one to display a list of 6 titles of all posts, except ones in category 13. Also, how do you end this loop.
    I so far have for this div section:

    <?php if (have_posts(3)) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>

    I also want the second div section to display a list of 10 posts (I have the code required to go in between the loop stuff)in all categories except in the featured category. Likewise, how should I go about ending this loop.
    I so far have for this:

    <?php if (have_posts()) : ?>
    			<?php while (have_posts()) : the_post(); ?>
    				<div class="post" id="post-<?php the_ID(); ?>">
    					<div class="postwrapper">
    						<a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading the rest of this entry »"><img src="<?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?>" alt="thumbnail" class="thumbnail" /></a>
    						<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    						<div class="entry">
    							<?php the_excerpt(); ?>
    						</div>
    					</div>
    					<div class="postmetadata">
    						<span class="thetime"><?php the_time('F jS, Y') ?></span>
    						<span class="thecategory"><?php the_category(', ') ?></span>
    						<?php edit_post_link('Edit', '<span class="editthispost">', '</span>'); ?>
    						<span class="thecomments"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span>
    						<div class="readmore">
    							<a href="<?php the_permalink() ?>" rel="bookmark" title="Continue reading the rest of this entry »">Read More</a>
    						</div>
    					</div>
    				</div>
    
    		<?php endwhile; ?>
    
    				<div class="navigation">
    					<div class="navleft"><?php next_posts_link('Older Entries') ?></div>
    					<div class="navright"><?php previous_posts_link('Newer Entries') ?></div>
    				</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    	<?php endif; ?>

    Any help would be much appreciated

    Kenneth

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    You might want to read up on Multiple Loops:

    http://codex.wordpress.org/The_Loop#Multiple_Loops

  3. kennethwatt
    Member
    Posted 5 years ago #

    Thanks Esmi, but for the following two pieces of code, how can I say how many posts to show, as it just uses the default from the Reading section of the WP Settings.

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    and

    <?php if (have_posts()) : ?>
    			<?php while (have_posts()) : the_post(); ?>

    Thanks

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    query_posts with the showposts parameter?

Topic Closed

This topic has been closed to new replies.

About this Topic