WordPress.org

Ready to get started?Download WordPress

Forums

Help limiting number of post... (8 posts)

  1. allshookup
    Member
    Posted 5 years ago #

    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; ?>
  2. allshookup
    Member
    Posted 5 years ago #

    anyone?

  3. kapiljain.in
    Member
    Posted 5 years ago #

    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.

  4. allshookup
    Member
    Posted 5 years ago #

    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...

  5. Jbert
    Member
    Posted 5 years ago #

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

    JIM

  6. allshookup
    Member
    Posted 5 years ago #

    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,

  7. kapiljain.in
    Member
    Posted 5 years ago #

    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

  8. allshookup
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.