How to display post according number using query_posts() in WordPress.

The query_posts function is used to easily modify the content returned for the default WordPress Loop.We can modify the content returned in $wp-query after the default database query has executed,fine-tune the query parameters,and re-execute the query using query_posts.

If we want to display number of posts then thequery_posts() function should be placed directly above the start of the Loop:

Example:-

The following example are to display only six post in WordPress.

query_posts( 'posts_per_page=6'&paged='.$paged );
if( have_posts() ):
    while( have_posts() ): the_post();
  //loop content(template tags,html,etc)

	echo '
	<li>';
	    the_title();
	    echo '</li>
	 ';
endwhile;
endif;
// Reset Query
wp_reset_query();
Total Page Visits: 2634 - Today Page Visits: 2

Leave a Reply