rakeshr

custom post type taxonomy parent terms sub terms search

Jan 3rd, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.63 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.  
  13. <?php
  14. if(isset($_POST['submit']))
  15. {
  16.     $name = $_POST['rrr'];
  17.     echo '<div style="margin:0 auto; width:100%; padding-bottom:5px; padding-top:15px; font-size:22px; color:#000;">You have searched for <span style="color:#EE2626;">' . $name .'</span>. Here are the results.</div>';
  18.  
  19. ?>
  20.  
  21.  
  22.  
  23. <?php
  24. $taxonomy = 'apptypes';
  25. $appargs = array( 'hide_empty' => 0, 'parent' => 0 );
  26.  
  27. //list terms in a given taxonomy
  28. $appterms = get_terms($taxonomy,$appargs);
  29. ?>
  30.  
  31. <?php
  32. foreach ($appterms as $appterm) {
  33. $termID = $appterm->term_id;
  34. $taxonomyName = $taxonomy;
  35. $termchildren = get_term_children( $termID, $taxonomyName );
  36. foreach ($termchildren as $child) {
  37.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  38.     $apppterm = strtolower($appterm->name);
  39.     $name = strtolower($name); 
  40.  
  41. if (strpos($apppterm, $name) === false  ) {
  42. } else {
  43.  
  44.     echo '<div style="margin:0 auto; width:100%; padding-bottom:5px; padding-top:15px; font-size:26px; color:#EE2626;">' . $appterm->name .'</div>';
  45.     echo $termsub->name;
  46.    
  47.    
  48.      $wpq = array (
  49.     'taxonomy' => $taxonomy,
  50.     'order' => 'ASC',
  51.     'term' => $termsub->slug
  52. );
  53. $query = new WP_Query ($wpq);
  54. $article_count = $query->post_count;
  55. echo '<table width="98%" border="0" cellspacing="0" cellpadding="5"  class="customtable">
  56.  <tr class="customhead">
  57.    <td align="left" valign="top">Year</td>
  58.    <td align="left" valign="top">Kit Name</td>
  59.    <td align="left" valign="top">Kit</td>
  60.  </tr>
  61.   <tr><td colspan="3">'.term_description($termsub->term_id,$taxonomyName) .'</td></tr>';   
  62.  
  63. if ($article_count) {
  64. $posts = $query->posts;
  65. foreach ($posts as $post) {
  66. include(MY_THEME_FOLDER . '/appsloop.php');
  67. }
  68. }
  69. echo ' </table>';
  70.  
  71. }
  72.    
  73.    
  74.  
  75. } }
  76. ?>
  77. <br /><br />
  78.  
  79.  
  80.  
  81. <?php } else { ?>
  82.  
  83. <form method="post" action="http://wpguru.in/themes/prothane/vehicle-applications/">
  84.    <table width="400" border="0" cellspacing="0" cellpadding="0">
  85.   <tr>
  86.     <td>Search by Manufacture:</td>
  87.     <td><input type="text" name="rrr" ></td>
  88.     <td><input type="submit" name="submit" value="Search"></td>
  89.   </tr>
  90.   <tr>
  91.     <td>&nbsp;</td>
  92.     <td>(Ex:Acura)</td>
  93.     <td>&nbsp;</td>
  94.   </tr>
  95. </table>
  96. </form>
  97. <?php
  98. $taxonomy = 'apptypes';
  99. // if show all is set
  100. if( isset($_GET['showall']) ):
  101.     $args = array( 'hide_empty' => 0 );
  102. else:
  103. // else show paged
  104.     $page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
  105.     // number of tags to show per-page
  106.     $per_page = 2;
  107.     $offset = ( $page-1 ) * $per_page;
  108.     $appargs = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0, 'parent' => 0 );
  109. endif;
  110. //list terms in a given taxonomy
  111. $appterms = get_terms($taxonomy,$appargs);
  112. ?>
  113.  
  114. <?php
  115. foreach ($appterms as $appterm) {
  116.  
  117. $termID = $appterm->term_id;
  118. $taxonomyName = $taxonomy;
  119. $termchildren = get_term_children( $termID, $taxonomyName );
  120. foreach ($termchildren as $child) {
  121.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  122.     echo '<div style="margin:0 auto; width:100%; padding-bottom:5px; padding-top:15px; font-size:26px; color:#EE2626;">' . $appterm->name.'</div>';
  123.     echo ''.$termsub->name.'';
  124.    
  125.    
  126.    
  127.    
  128.    
  129.      $wpq = array (
  130.     'taxonomy' => $taxonomy,
  131.     'order' => 'ASC',
  132.     'term' => $termsub->slug
  133. );
  134. $query = new WP_Query ($wpq);
  135. $article_count = $query->post_count;
  136. echo '<table width="98%" border="0" cellspacing="0" cellpadding="5"  class="customtable">
  137.  <tr class="customhead">
  138.    <td align="left" valign="top">Year</td>
  139.    <td align="left" valign="top">Kit Name</td>
  140.    <td align="left" valign="top">Kit</td>
  141.  </tr>
  142.   <tr><td colspan="3">'.term_description($termsub->term_id,$taxonomyName) .'</td></tr>';   
  143.  
  144. if ($article_count) {
  145. $posts = $query->posts;
  146. foreach ($posts as $post) {
  147. include(MY_THEME_FOLDER . '/appsloop.php');
  148. }
  149. }
  150. echo ' </table>';
  151.    
  152.    
  153.    
  154.    
  155.    
  156.    
  157.     echo '';
  158. } }
  159. ?>
  160. <br /><br />
  161.  
  162. <?php
  163. $Path=home_url( '/' );
  164. $URI= $Path.'vehicle-applications/';
  165.  
  166. ?>
  167.  
  168. <?php if( !isset($_GET['showall']) ):
  169.     $total_terms = wp_count_terms( 'apptypes', $appargs );
  170.     $pages = ceil($total_terms/$per_page);
  171.     // if there's more than one page
  172.     if( $pages > 1 ):
  173.         for ($pagecount=1; $pagecount <= $pages; $pagecount++):
  174.             echo '<a href="'.$URI.'page/'.$pagecount.'/" style="padding:5px;">'.$pagecount.'</a> ';
  175.         endfor;
  176.         // link to show all
  177.         echo '<a href="'.$URI.'?showall=true">show all</a>';
  178.     endif;
  179. else:
  180. // showall is set, show link to get back to paged mode
  181.     echo '<a href="'.$URI.'">show paged</a>';
  182. endif;
  183.  
  184. }
  185. ?>
  186.  
  187.  
  188.  
  189.   </div>
  190.    
  191.  
  192.  
  193.  
  194. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment