Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <?php get_header(); ?>
  2.  
  3. <main role="main" class="blinds">
  4.  
  5. <h1 class="main-product-title">Products</h1>
  6.  
  7. <!-- section -->
  8. <section class="main-product-content">
  9.  
  10. <h2><?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h2>
  11.  
  12. <?php if (have_posts()): while (have_posts()) : the_post(); ?>
  13.  
  14. <!-- article -->
  15. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  16. <!-- post image -->
  17. <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
  18.  
  19. <?php the_post_thumbnail(array(720,400)); // Declare pixel size you need inside the array ?>
  20.  
  21. <?php endif; ?>
  22. <!-- /post thumbnail -->
  23.  
  24. <!-- post title -->
  25. <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
  26. <!-- /post title -->
  27.  
  28. <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">View ></a></p>
  29.  
  30. </article>
  31.  
  32. <!-- /article -->
  33.  
  34. <?php endwhile; ?>
  35.  
  36. <?php else: ?>
  37.  
  38. <!-- article -->
  39. <article>
  40. <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
  41. </article>
  42. <!-- /article -->
  43.  
  44. <?php endif; ?>
  45.  
  46. <?php get_template_part('pagination'); ?>
  47.  
  48. </section>
  49. <!-- /section -->
  50.  
  51. <div class="sidebar-wrapper">
  52. <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('product-sidebar')) ?>
  53. </div>
  54.  
  55. </main>
  56.  
  57. <?php
  58. // get the term...
  59. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  60.  
  61. // get all posts from this term and store the IDs
  62. $term_posts = get_posts(array('tax_query' => array(array(
  63. 'taxonomy' => get_query_var('taxonomy'),
  64. 'terms' => $term->ID
  65. ))));
  66. $term_posts_IDs = array();
  67. foreach ($term_posts as $term_post) {
  68. $term_posts_IDs[] = $term_post->ID;
  69. }
  70.  
  71. // get the available styles from this set of posts
  72. $styles = wp_get_object_terms($term_posts_IDs, 'style');
  73.  
  74. ?>
  75. <h2><?php echo $term->name; ?></h2>
  76. <?php
  77. if(!empty($styles)): // styles are availables for this term
  78. foreach($styles as $style):
  79. ?>
  80. <h3><?php echo $term->name; ?> > <?php echo $style->name; ?></h3>
  81. <?php
  82. // get the first three products with colour + style
  83. $tax_posts = get_posts(array(
  84. 'posts_per_page' => 3,
  85. 'tax_query' => array(
  86. 'relation' => 'AND',
  87. array(
  88. 'taxonomy' => get_query_var('taxonomy'),
  89. 'terms' => $term->ID
  90. ),
  91. array(
  92. 'taxonomy' => 'style',
  93. 'terms' => $style->ID
  94. )
  95. )
  96. ));
  97. ?>
  98. <ul>
  99. <?php foreach($tax_posts as $tax_post): ?>
  100. <li><?php echo $tax_post->post_title; ?></li>
  101. <?php endforeach; ?>
  102. </ul>
  103. <!-- ... link to your style taxonomy template here ... -->
  104. <?pgpp endforeach ; ?>
  105. <?php else : ?>
  106. <!-- ... default behaviour ... -->
  107. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement