Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created March 24, 2012 00:44
Show Gist options
  • Save mikejolley/2176823 to your computer and use it in GitHub Desktop.
Save mikejolley/2176823 to your computer and use it in GitHub Desktop.

Revisions

  1. mikejolley revised this gist Mar 25, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@ if ( is_singular('product') ) {
    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $cats_array[] = $term->term_id;

    $query_args = array( 'posts_per_page' => 5, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
    $query_args = array( 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
    array(
    'taxonomy' => 'product_cat',
    'field' => 'id',
    'terms' => $cats_array
    ));
    )));

    $r = new WP_Query($query_args);

  2. mikejolley renamed this gist Mar 24, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. mikejolley created this gist Mar 24, 2012.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <?php

    if ( is_singular('product') ) {

    global $post;

    // get categories
    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $cats_array[] = $term->term_id;

    $query_args = array( 'posts_per_page' => 5, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
    array(
    'taxonomy' => 'product_cat',
    'field' => 'id',
    'terms' => $cats_array
    ));

    $r = new WP_Query($query_args);

    if ($r->have_posts()) {
    ?>
    <ul class="product_list_widget">
    <?php while ($r->have_posts()) : $r->the_post(); global $product; ?>
    <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>">
    <?php if (has_post_thumbnail()) the_post_thumbnail('shop_thumbnail'); else echo '<img src="'. woocommerce_placeholder_img_src() .'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_thumbnail_image_width').'" height="'.$woocommerce->get_image_size('shop_thumbnail_image_height').'" />'; ?>
    <?php if ( get_the_title() ) the_title(); else the_ID(); ?>
    </a> <?php echo $product->get_price_html(); ?></li>
    <?php endwhile; ?>
    </ul>
    <?php
    // Reset the global $the_post as this query will have stomped on it
    wp_reset_query();

    }

    }
    ?>