Advertisement
tenten71

WordPress Custom Taxonomy Template with Sub Categories

Jun 19th, 2012
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. <?php
  2. $fabricTerms = get_terms( 'fabric-category'); // ..find sub-categories of 'fabric-category'
  3. foreach($fabricTerms as $fabricTerm){
  4. ?>
  5. <div class="fabricCategory">
  6. <h2 class="fabrics"><?php echo $fabricTerm->name; ?></h2>
  7.  
  8. <?php
  9. global $wpdb;
  10. // create blank array..
  11. $fabricPosts = array();
  12. // find term_id for sub-category..
  13. $fabric_category_term_id = $wpdb->get_results( "SELECT term_id FROM {$wpdb->terms} WHERE name = '".$fabricTerm->name."' " );
  14. foreach($fabric_category_term_id as $fc_id){
  15. // find taxonomy_ids from term_id..
  16. $fabric_taxonomy_id = $wpdb->get_results( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = ".$fc_id->term_id." " );
  17. foreach($fabric_taxonomy_id as $ft_id){
  18. // find object_id from taxonomy_id..
  19. $fabric_object_id = $wpdb->get_results( "SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = ".$ft_id->term_taxonomy_id." " );
  20. foreach($fabric_object_id as $fo_id){
  21. // add object_id to array..
  22. array_push($fabricPosts, $fo_id->object_id);
  23. }
  24. }
  25. }
  26. // if less than 5 posts, get number of posts to detirmine number of loops..
  27. if( count($fabricPosts) < 5 ){
  28. $loops = count($fabricPosts);
  29. }
  30. else {
  31. $loops = 5;
  32. }
  33. // loop through posts..
  34. for($v=0; $v<$loops; $v++){
  35. // get the 1st element from the array..
  36. $fabricPost = array_shift($fabricPosts);
  37. // get post data..
  38. $post = get_post($fabricPost);
  39. ?>
  40. <div class="archive">
  41. <div class="thumbnail"><a href="<?php the_permalink() ?>" title="View <?php $name = get_post_meta($post->ID, 'Fabric Name', true); echo $name; ?> - <?php the_title_attribute(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a></div>
  42. <h3 class="archiveName" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" title="View <?php $name = get_post_meta($post->ID, 'Fabric Name', true); echo $name; ?> - <?php the_title_attribute(); ?>"><?php $name = get_post_meta($post->ID, 'Fabric Name', true); echo $name; ?></a></h3>
  43. <ul class="archiveColor"><?php
  44. $colors = get_the_terms($post->ID, 'color');
  45. foreach($colors as $color){
  46. echo "<li><a href='";
  47. echo bloginfo('url');
  48. echo "/color/".$color->name."'>";
  49. echo $color->name."</a></li>";
  50. } // end foreach
  51. ?></ul>
  52. <p class="archiveNumber"><?php the_title(); ?></p>
  53. </div>
  54. <?php
  55. }
  56. ?>
  57.  
  58. <p class="moreArrow"><a href="<?php bloginfo('url'); ?>/fabric-category/<?php echo $fabricTerm->slug; ?>" title="more fabrics in the <?php echo $fabricTerm->name; ?> category">&nbsp;</a></p>
  59. </div>
  60. <?php
  61. } // end foreach
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement