Barbareshet

cpt loop

Jul 26th, 2017
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The cpt template
  4.  
  5.  
  6. get_header();
  7.  
  8. $arg = array(
  9. 'post_type' => 'cpt_name',
  10. 'posts_per_page'    =>  5
  11. );
  12. //create your personal query
  13. $my_query = new WP_Query($args);
  14.                 if ( $my_query->have_posts() ) :
  15.  
  16.                
  17.  
  18.                     /* Start the Loop */
  19.                     while ( $my_query->have_posts() ) : $my_query->the_post();
  20.  
  21.                         /*
  22.                          * Include the Post-Format-specific template for the content.
  23.                          * If you want to override this in a child theme, then include a file
  24.                          * called content-___.php (where ___ is the Post Format name) and that will be used instead.
  25.                          */
  26.                         get_template_part( 'template-parts/content', get_post_format() );
  27.  
  28.                    wp_reset_query();
  29.                  endwhile;?>
  30.  
  31.                     <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
  32.                     <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
  33.  
  34.              <?php   else :
  35.  
  36.                     get_template_part( 'template-parts/content', 'none' );
  37.  
  38.                 endif;
  39.  
  40. get_footer();
Advertisement
Add Comment
Please, Sign In to add comment