0

I have 1 important taxonomy that contains 2 different custom post type content. I want somehow show them in same taxonomy page with both paging. Well.. i am not sure i can do that or not. Is it possible to paging 2 different CPT in same taxonomy?

1

You can create two separate loops with pagination - and place them in side by side div containers - with pagination links inside each div. You would include the pagination links in each div, because you might have more of one post type then the other, and therefor more pages than the other.

The columns will paginate together unless you use ajax javascript to refresh the content of the div's independently - in which case you'll have to pass the correct relative page number in your call.

Without the ajax, with separate columns of post types paging in tandem, your template would look like this (untested code):

<?php
/*
 Template Name: Side-by-Side Paginated Custom Post Types
*/
  global $query_string;
  global $wp_query;

  get_header(); 

  $myquery = wp_parse_args($query_string);
  $myquery['tax_query'] = $wp_query->tax_query;

  echo '<div id="container">';

    // Work whether query var is page or paged
    if ( get_query_var('paged') ) 
      { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) 
      { $paged = get_query_var('page');
    } else 
      { $paged = 1; }

    $myquery['post_status']  = 'publish';
    $myquery['paged']        = '.$paged';

    // Create Page Heading, including each term from the query
    // Allows for advanced tax query with more than one taxonomy term, such as News and Events in the same query

    foreach ($wp_query->tax_query->queries as $taxterm) {
     if ('your_taxonomy' == $taxterm['taxonomy']) {

       $last_term = end( array_keys( $taxterm['terms'] ) ); // Mark the last topic

         echo "<h1>";
         foreach ($taxterm['terms'] as $k => $termid) {
           $termobj = get_term_by( $taxterm['field'], $termid, $taxterm['taxonomy'] );
           echo $termobj->name;
           if ( $k !== $last_term ) echo ' &amp; ';
         }
         echo "</h1>";
     }
    }

    echo '<div class="left-column">'; 

      $myquery['post_type']    = 'your_cpt_1';

      echo '<h2 class="sec1 title">Custom Posts 1</h2>';
      // Query
      $myquery = new WP_query( $args );
        if ( $myquery->have_posts() ) : while ( $myquery->have_posts() ) : $myquery->the_post(); 

      get_template_part( 'content', 'your_cpt_1' );

      endwhile; else :
      endif;

      echo '<div class="pagination">';
        echo '<div class="alignleft">'; previous_posts_link('Previous'); echo '</div>';
        echo '<div class="alignright">'; next_posts_link('Next'); echo '</div>';
      echo '</div> <!-- end pagination -->';

      wp_reset_postdata();      

    echo '</div> <!-- div class="left-column" -->'; 

    echo '<div class="right-column">'; 

      $myquery['post_type']    = 'your_cpt_2';
      echo '<h2 class="sec1 title">Custom Posts 2</h2>';
      // Query
      $myquery = new WP_query( $args );
        if ( $myquery->have_posts() ) : while ( $myquery->have_posts() ) : $myquery->the_post(); 

      get_template_part( 'content', 'your_cpt_2' );

      endwhile; else :
      endif;

      echo '<div class="pagination">';
        echo '<div class="alignleft">'; previous_posts_link('Previous'); echo '</div>';
        echo '<div class="alignright">'; next_posts_link('Next'); echo '</div>';
      echo '</div> <!-- end pagination -->';

      wp_reset_postdata();      
    echo '</div> <!-- div class="right-column" -->'; 

  echo '</div> <!-- div id="container" -->'; 

get_footer();
?>
0

I think you're saying you have 2 post types which each share the same taxonomy term.

Create a template that queries both post types and single taxonomy:

query_posts( array('post_type' => array('post_type_one', 'post_type_two'), 'tax_slug' => 'term_name' ) );
1
  • well i dont want 1 list contains 2 CPT.. Somehow there must be 2 different paging May 20 '11 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.