Advertisement
rakeshr

paginated taxonomy list with error in page urls

Nov 16th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.73 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Applications
  4. */
  5.  
  6.  
  7.  
  8. get_header(); ?>
  9.  
  10. <div id="ppagewrapper" >       
  11.  <?php
  12. // if show all is set
  13. if( isset($_GET['showall']) ):
  14.     $args = array( 'hide_empty' => 0 );
  15. else:
  16. // else show paged
  17.     $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
  18.     // number of tags to show per-page
  19.     $per_page = 5;
  20.     $offset = ( $page-1 ) * $per_page;
  21.     $args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0 );
  22. endif;
  23. $taxonomy = 'apptypes';
  24. $appterms = get_terms( $taxonomy, $args );
  25. foreach ($appterms as $appterm) {
  26.    
  27. $termID = $appterm->term_id;
  28. $taxonomyName = $taxonomy;
  29. $termchildren = get_term_children( $termID, $taxonomyName );
  30. foreach ($termchildren as $child) {
  31.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  32.     echo '<div style="margin:0 auto; width="100%"><h2>'. $appterm->name.'</h2></div>';
  33.     echo $termsub->name;
  34.    
  35.      $wpq = array (
  36.     'taxonomy' => $taxonomy,
  37.     'term' => $termsub->slug
  38. );
  39. $query = new WP_Query ($wpq);
  40. $article_count = $query->post_count;
  41. echo '<table width="98%" border="0" cellspacing="0" cellpadding="5"  class="customtable">
  42.  <tr class="customhead">
  43.    <td align="left" valign="top">Year</td>
  44.    <td align="left" valign="top">Kit Name</td>
  45.    <td align="left" valign="top">Kit</td>
  46.  </tr>
  47.   <tr><td colspan="3">'.term_description($termsub->term_id,$taxonomyName) .'</td></tr>';   
  48.  
  49. if ($article_count) {
  50. $posts = $query->posts;
  51. foreach ($posts as $post) {
  52. include(MY_THEME_FOLDER . '/appsloop.php');
  53. }
  54. }
  55. echo ' </table>';
  56.    
  57.    
  58.    
  59.    
  60.    
  61.    
  62.    
  63.    
  64. }}
  65. echo '<table width="980" ><tr><td>';
  66. // pagination
  67. // if showall isn't set
  68. if( !isset($_GET['showall']) ):
  69.     $total_terms = wp_count_terms( 'apptypes' );
  70.     $pages = ceil($total_terms/$per_page);
  71.     // if there's more than one page
  72.     if( $pages > 1 ):
  73.         for ($pagecount=1; $pagecount <= $pages; $pagecount++):
  74.             echo '<a href="'.get_permalink().'page/'.$pagecount.'/" style="padding:5px;">'.$pagecount.'</a> ';
  75.         endfor;
  76.         // link to show all
  77.         echo '<a href="'.get_permalink().'?showall=true">show all</a>';
  78.     endif;
  79. else:
  80. // showall is set, show link to get back to paged mode
  81.     echo '<a href="'.get_permalink().'">show paged</a>';
  82. endif;
  83. echo '</td></tr></table>';
  84. ?>
  85.  
  86.  
  87.  
  88.  
  89. <?php
  90. //list terms in a given taxonomy
  91. /*$page = ( get_query_var('page') ) ? get_query_var( 'page' ) : 1;
  92.     // number of tags to show per-page
  93.     $per_page = 5;
  94.     $offset = ( $page-1 ) * $per_page;
  95.     $appargs = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0 );
  96.    
  97. $taxonomy = 'apptypes';
  98. $appterms = get_terms($taxonomy,$appargs);
  99.  
  100. foreach ($appterms as $appterm) {
  101.  
  102. $termID = $appterm->term_id;
  103. $taxonomyName = $taxonomy;
  104. $termchildren = get_term_children( $termID, $taxonomyName );
  105. foreach ($termchildren as $child) {
  106.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  107.     echo '<div style="margin:0 auto; width="100%"><h2>'. $appterm->name.'</h2></div>';
  108.     echo $termsub->name;
  109.  
  110.  
  111.   $wpq = array (
  112.     'taxonomy' => $taxonomy,
  113.     'term' => $termsub->slug
  114. );
  115. $query = new WP_Query ($wpq);
  116. $article_count = $query->post_count;
  117. echo '<table width="98%" border="0" cellspacing="0" cellpadding="5"  class="customtable">
  118.   <tr class="customhead">
  119.     <td align="left" valign="top">Year</td>
  120.     <td align="left" valign="top">Kit Name</td>
  121.     <td align="left" valign="top">Kit</td>
  122.   </tr>
  123.   <tr><td colspan="3">'.term_description($termsub->term_id,$taxonomyName) .'</td></tr>';   
  124.  
  125. if ($article_count) {
  126. $posts = $query->posts;
  127. foreach ($posts as $post) {
  128. include(MY_THEME_FOLDER . '/appsloop.php');
  129. }
  130. }
  131. echo ' </table>';  } }*/
  132.  
  133.  
  134. ?>
  135.  
  136.  
  137.  
  138.  
  139.    
  140.   </div>
  141.    
  142.  
  143.  
  144.  
  145. <?php get_footer(); ?>
  146.  
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement