Advertisement
rakeshr

final-customposttype-mainterm-subterm-posts code

Jan 2nd, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Applications
  4. */
  5.  
  6.  
  7.  
  8. get_header(); ?>
  9.  
  10. <div id="ppagewrapper" >       
  11.  
  12. <?php
  13. $taxonomy = 'apptypes';
  14. // if show all is set
  15. if( isset($_GET['showall']) ):
  16.     $args = array( 'hide_empty' => 0 );
  17. else:
  18. // else show paged
  19.     $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
  20.     // number of tags to show per-page
  21.     $per_page = 2;
  22.     $offset = ( $page-1 ) * $per_page;
  23.     $appargs = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0, 'parent' => 0 );
  24. endif;
  25. //list terms in a given taxonomy
  26. $appterms = get_terms($taxonomy,$appargs);
  27. ?>
  28.  
  29. <?php
  30. foreach ($appterms as $appterm) {
  31.  
  32. $termID = $appterm->term_id;
  33. $taxonomyName = $taxonomy;
  34. $termchildren = get_term_children( $termID, $taxonomyName );
  35. foreach ($termchildren as $child) {
  36.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  37.     echo '<div style="margin:0 auto; width:100%; padding-bottom:5px; padding-top:15px; font-size:26px; color:#EE2626;">' . $appterm->name.'</div>';
  38.     echo ''.$termsub->name.'';
  39.    
  40.    
  41.    
  42.    
  43.    
  44.      $wpq = array (
  45.     'taxonomy' => $taxonomy,
  46.     'order' => 'ASC',
  47.     'term' => $termsub->slug
  48. );
  49. $query = new WP_Query ($wpq);
  50. $article_count = $query->post_count;
  51. echo '<table width="98%" border="0" cellspacing="0" cellpadding="5"  class="customtable">
  52.  <tr class="customhead">
  53.    <td align="left" valign="top">Year</td>
  54.    <td align="left" valign="top">Kit Name</td>
  55.    <td align="left" valign="top">Kit</td>
  56.  </tr>
  57.   <tr><td colspan="3">'.term_description($termsub->term_id,$taxonomyName) .'</td></tr>';   
  58.  
  59. if ($article_count) {
  60. $posts = $query->posts;
  61. foreach ($posts as $post) {
  62. include(MY_THEME_FOLDER . '/appsloop.php');
  63. }
  64. }
  65. echo ' </table>';
  66.    
  67.    
  68.    
  69.    
  70.    
  71.    
  72.     echo '';
  73. } }
  74. ?>
  75. <br /><br />
  76.  
  77. <?php
  78. $Path=home_url( '/' );
  79. $URI= $Path.'vehicle-applications/';
  80. echo $URI;
  81. ?>
  82.  
  83. <?php if( !isset($_GET['showall']) ):
  84.     $total_terms = wp_count_terms( 'apptypes', $appargs );
  85.     $pages = ceil($total_terms/$per_page);
  86.     // if there's more than one page
  87.     if( $pages > 1 ):
  88.         for ($pagecount=1; $pagecount <= $pages; $pagecount++):
  89.             echo '<a href="'.$URI.'page/'.$pagecount.'/" style="padding:5px;">'.$pagecount.'</a> ';
  90.         endfor;
  91.         // link to show all
  92.         echo '<a href="'.$URI.'?showall=true">show all</a>';
  93.     endif;
  94. else:
  95. // showall is set, show link to get back to paged mode
  96.     echo '<a href="'.$URI.'">show paged</a>';
  97. endif;
  98. ?>
  99.  
  100.   </div>
  101.    
  102.  
  103.  
  104.  
  105. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement