How to show Multiple post in wordpress on single page?

18:29:00 0 Comments A+ a-

In wordpress you can show your post many way. All are depend on your needs and website requirement like many time you want to show only one post and many time you want to multiple post in a page. we are already discussed about that how can we show single post in our website.

Now we learn how we show multiple post in sinlge page.

You have just put this code to your php page given below
 
             
   
       



Now all posts are showing on your page.



====================================================


but if you want to show limited post on your page then you will edit your code like this
$query = new WP_Query( array('posts_per_page'=> '5') ); 

 

 if ( $query->have_posts() ) : 
       while ( $query->have_posts() ) : $query->the_post();
             get_template_part( 'content', get_post_format() ); 
       endwhile; 
  endif;

  
$query = new WP_Query( array('posts_per_page'=> '5') ); 
 
 if ( $query->have_posts() ) : 
       while ( $query->have_posts() ) : $query->the_post();
             get_template_part( 'content', get_post_format() ); 
       endwhile; 
  endif;
 
==================================================

and if you want to show post of any single category then you can edit your code like this


$query = new WP_Query( array('category_name'=>'news',  
                             'posts_per_page'=> '5') ); 
  if ( $query->have_posts() ) : 
       while ( $query->have_posts() ) : $query->the_post();
             get_template_part( 'content', get_post_format() ); 
       endwhile; 
  endif;


in above code i have just add category name which is news


For more information about WordPress learn my blog continuously ..... thanks