Skip to content

Instantly share code, notes, and snippets.

@dn7734
Created December 19, 2016 11:43
Show Gist options
  • Save dn7734/f0789d3e7f622e10240003a8ef98c684 to your computer and use it in GitHub Desktop.
Save dn7734/f0789d3e7f622e10240003a8ef98c684 to your computer and use it in GitHub Desktop.
display products for a specific taxonomy term
<?php $term_title = single_term_title('', 0); ?>
<?php echo '<h2 class="block-title">' . $term_title . '</h2>'; ?>
<?php $description = term_description();
echo $description; ?>
<?php $term_slug = get_queried_object()->slug;
if ( !$term_slug )
return;
else
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'products',
'field' => 'slug',
'terms' => $term_slug,
'posts_per_page' => 4
)
)
);
$loop = new WP_Query( $args ); ?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<article <?php post_class(); ?>>
<div class="entry-content">
<?php $product_price = get_field('product_price') //acf ?>
<?php if ( has_post_thumbnail()) { ?>
<a href="<?php echo the_permalink();?>" title="<?php echo the_title(); ?>">
<?php the_post_thumbnail('thumbnail', array( 'class' =>' img-responsive product-img ' )); ?>
</a>
<?php } ?>
<a href="<?php echo the_permalink();?>" title="<?php echo the_title(); ?>">
<h4 class="entry-title"><?php the_title(); ?></h4>
</a>
<a href="<?php echo the_permalink();?>" title="<?php echo the_title(); ?>" class="btn btn-default price-btn">
$ <?php echo $product_price; ?>.00
</a>
</div>
</article>
</li>
<?php endwhile; // End the loop. ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment