Advertisement
marjwyatt

custom post type archive with pagination

Jan 24th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Adverts Archive
  4. See http://schema.org/Product for details of itemprop classifications
  5. */
  6.  
  7. // Add a link after excerpt to read the ad
  8. add_filter( 'excerpt_more', 'new_excerpt_more' );
  9. function new_excerpt_more( $more ) {
  10.     return '<p><b><a class="read-more" href="'. get_permalink( get_the_ID() ) . '">~ Read the Ad ~</a></b></p>';
  11. }
  12.  
  13. add_filter('genesis_pre_get_option_site_layout', '__genesis_return_full_width_content');
  14. remove_action('genesis_loop', 'genesis_do_loop');
  15. add_action('genesis_loop', 'vm_custom_adverts_archive_loop');
  16. function vm_custom_adverts_archive_loop() {
  17.     //global $paged;
  18.     $paged = ( get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
  19.     $args = array(
  20.         'posts_per_page' => 3,
  21.         'post_type' => 'adverts',
  22.         'paged' => $paged,
  23.         'orderby' => 'date',
  24.         'order' => 'DESC'
  25.     );
  26.     global $vm_query;
  27.     $vm_query = new WP_Query ( $args );
  28.     if ($vm_query->have_posts()) : // custom query for primary post content
  29.         while ($vm_query->have_posts()) : $vm_query->the_post(); /*$do_not_duplicate = $post->ID;*/
  30.         global $paged;
  31.         $total_pages = $vm_query->max_num_pages;
  32.         $postID = get_queried_object()->ID;
  33.         $thePostID = get_the_ID();
  34.         $postTitle = get_the_title($postID);
  35.         $postThumb = ( get_post_meta($thePostID, '_vm_adThumb1', true) ); ?>
  36.         <div itemscope itemtype="http://schema.org/Service">
  37.         <?php echo '<h2><a href="'. get_permalink($post->$postID) .'"><span itemprop="name">' . $postTitle .'</span></a></h2>'; ?>
  38.         <div class="adCopy entry">
  39.             <?php
  40.                 echo '<div class="entry-content" itemprop="serviceType">'; // echo out schema property
  41.                 echo '<div class="one-fifth first"><a href="' . $postThumb . '" rel="lightbox"><img height="150" width="150" itemprop="image" alt="'.$postTitle.'" class="alignleft post-image entry-image" src="' . $postThumb . '"/></a></div>';
  42.                 echo '<div class="four-fifths last">'.( wpautop (the_excerpt()) ).'</div>'; // using post content as song description, preserve paragraphs with wpautop
  43.                 echo '</div>';
  44.             ?>
  45.         </div>
  46.         </div><!-- end Item Scope -->
  47.         <?php
  48.         endwhile;
  49.         // Ref Link: http://wp.tutsplus.com/tutorials/wordpress-pagination-a-primer/
  50.         // Ref link: http://codex.wordpress.org/Function_Reference/paginate_links
  51.         $big = 999999999; // need an unlikely integer
  52.         echo paginate_links( array(
  53.             'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  54.             'format' => '?paged=%#%',
  55.             'current' => max( 1, get_query_var('paged') ),
  56.             'total' => $vm_query->max_num_pages
  57.         ) );
  58.         do_action( 'genesis_after_endwhile' );
  59.         endif;
  60.         wp_reset_query();
  61. }
  62. genesis(); // <- everything important: make sure to include this.
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement