• Hello – I am using the code below. How do I modify it so that it only displays the latest three posts? Thanks for your help!!

    <?php query_posts('category_name='.get_the_title()); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<div>
    	<h3><?php the_title(); ?></h3>
    	<p><?php the_content(); ?></p>
    	</div>
    <?php endwhile; else: ?>no match<?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • why not use get_posts instead..

    <?php
    $args = array( 'numberposts' => 3, 'category' => 1 ); /* change category id */
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    <div>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content(); ?></p>
    </div>
    <?php endforeach; ?>

    if using query_posts then set param 'posts_per_page=3'..
    but ensure you reset main loop by calling wp_reset_query() afterwards.

    If you only want to show three posts per page then go into SETTINGS >> READING and change “Blog pages show at most” to 3.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Only Show 3 Posts (PHP Coding)’ is closed to new replies.