Support » Themes and Templates » Help limiting number of post…

  • How can I limit the number of post to just 3?

    Here is the code I am using on my current theme…
    I have tried several things but they just mess up the code. I am not a php coder but, I’m sure someone here know what to do…
    Thanks for your help,

    <?php $i = 0; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); $i++; ?>
    <div class="span-8 post-<?php the_ID(); ?><?php if ($i == 3) { ?> last<?php  } ?>">
    <h6 class="archive-header"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title() ?></a></h6>
    <?php echo get_the_image_link(array('thumbnail','thumbnail-news'),'thumbnail'); ?>
    <?php the_excerpt(); ?>
    <p class="postmetadata"><?php the_time('M d, Y') ?> | <?php comments_popup_link('Have your say »', '1 Comment »', '% Comments »'); ?></p>
    </div>
    <?php if ($i == 3) { ?><div class="archive-stack clear"></div><?php $i = 0; } ?>
    <?php endwhile; endif; ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • anyone?

    You can set number of post in a page from wordpress admin.

    Go to wp-admin > Settings > Reading and change the value of Blog pages show at most textbox to 3.

    You can set number of post in a page from wordpress admin.

    Go to wp-admin > Settings > Reading and change the value of Blog pages show at most textbox to 3.

    That has nothing to do with what I am trying to do or the code above.

    My site is http://www.lukeshook.com I only want to display 3 post excerpts under the main image / article. Right now it is showing 4 or more if I post them.

    The code in the first post is from my home page and is what controls how the post are displayed.

    Can someone help me?
    Thanks…

    did u ever solve this? Be sure to look at plugin ‘Different Post per page’

    JIM

    ummm…maybe I’m not being clear…
    I don’t need a plugin…
    I just need to know how to edit the code above so that it only pulls three post not all.

    Thanks,

    Hi,

    Use the following code, hope works for you.

    <?php $i = 0; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    	if( $post->ID == $do_not_duplicate ) continue;
    	update_post_caches($posts);
    	$i++;
    	if ($i<=3) {?>
    		<div class="span-8 post-<?php the_ID(); ?>
    			<?php if ($i == 3) { ?> last<?php  } ?>">
    			<h6 class="archive-header"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title() ?></a></h6>
    			<?php echo get_the_image_link(array('thumbnail','thumbnail-news'),'thumbnail'); ?>
    			<?php the_excerpt(); ?>
    			<p class="postmetadata"><?php the_time('M d, Y') ?> | <?php comments_popup_link('Have your say »', '1 Comment »', '% Comments »'); ?></p>
    		</div>
    	<?php } ?>
    <?php endwhile; endif; ?>
    <div class="archive-stack clear"></div>

    Thanks
    Kapil

    kapiljain.in you are amazing!
    Thank you so much for your help. It worked like a charm!
    Because of people like you that are willing to help others wordpress continues to grow.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help limiting number of post…’ is closed to new replies.