Standard / Global method of WP Query with Navigation

banner-image

If you want to display the post, page, or any post-type on your custom templates, just use the below query on the template file. The below code also provides pagination ($paged) options if you want.

if (have_posts())
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;//optional for pagination
    $wp_query = new WP_Query( array( 'post_type' => 'post/page/post_type','showposts' => '3', 'order'=>'ASC', 'paged' => $paged) );

    while ($wp_query->have_posts()) : $wp_query->the_post();
        the_title();
        the_permalink();
        the_content();
    endwhile; 
    
    posts_nav_link( ' · ', 'Previous Posts', 'Next Posts' );
    wp_reset_query();
endif;

 

Or you can use the below method if you want. Both the query should work properly.

 

global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args =  array('post_type' => 'post/page/post_type' ,'posts_per_page' => 3,  'paged' => $paged) ;
query_posts( $args );

#----------------------------------------------------->
if (have_posts()) while (have_posts()) : the_post();
  	the_title();
    the_post_thumbnail(array(100, 100));?>
    <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>" alt="">
    <?php the_content();
endwhile; wp_reset_query();
#------------------------------- End of Query ------------------------------->

 

Cheers!

Tags:

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x