function foxyshop_related_products($sectiontitle = "Related Products", $maxproducts = 5) { global $product, $post, $foxyshop_settings; $related_order = ""; $args = array('post_type' => 'foxyshop_product', "post__not_in" => array($product['id'])); //Native Related Products if ($foxyshop_settings['related_products_custom'] && $product['related_products']) { $args['post__in'] = explode(",", $product['related_products']); $args['posts_per_page'] = -1; if ($related_order = get_post_meta($product['id'], "_related_order", 1)) { add_filter('posts_orderby', 'foxyshop_related_order'); } //Tags } elseif ($foxyshop_settings['related_products_tags']) { $tags = wp_get_post_terms($product['id'], 'foxyshop_tags', array("fields" => "ids")); if (count($tags) > 0) { $args['tax_query'] = array(array('taxonomy' => 'foxyshop_tags', 'field' => 'id', 'terms' => $tags)); $args['posts_per_page'] = $maxproducts; $args['orderby'] = "rand"; } else { $args['post__in'] = array("-1"); } } else { return; } if (!array_key_exists('orderby', $args)) { $args = array_merge($args, foxyshop_sort_order_array()); } $relatedlist = new WP_Query($args); if (count($relatedlist->posts) > 0) { $original_product = $product; echo '<ul class="foxyshop_related_product_list">'; echo '<li class="titleline"><h3>' . $sectiontitle . '</h3></li>'; while ($relatedlist->have_posts()) { $relatedlist->the_post(); $product = foxyshop_setup_product(); $thumbnailSRC = foxyshop_get_main_image(apply_filters('foxyshop_related_products_thumbnail_size', "thumbnail")); $write = '<li class="foxyshop_product_box">' . "\n"; $write .= '<div class="foxyshop_product_image">'; $write .= '<a href="' . $product['url'] . '"><img src="' . $thumbnailSRC . '" alt="' . esc_attr($product['name']) . '" class="foxyshop_main_image" /></a>'; $write .= "</div>\n"; $write .= '<div class="foxyshop_product_info">'; $write .= '<h2><a href="' . $product['url'] . '">' . apply_filters('the_title', $product['name']) . '</a></h2>'; $write .= foxyshop_price(0, 0); $write .= "</div>\n"; $write .= '<div class="clr"></div>'; $write .= "</li>\n"; echo apply_filters('foxyshop_related_products_html', $write, $product); } echo "</ul>\n"; echo '<div class="clr"></div>'; $product = $original_product; wp_reset_postdata(); } if ($related_order) { remove_filter('posts_orderby', 'foxyshop_related_order'); } }
<?php foxyshop_include('header'); ?> <div id="foxyshop_container"> <?php //Write Category Title echo '<h1 id="foxyshop_category_title">Products</h1>' . "\n"; //Write Product Sort Dropdown //foxyshop_sort_dropdown(); //Feel free to put a store description here //echo '<p></p>'."\n"; //Run the query for all products in this category global $paged, $wp_query; $paged = get_query_var('page'); $args = array('post_type' => 'foxyshop_product', 'post_status' => 'publish', 'posts_per_page' => foxyshop_products_per_page(), 'paged' => get_query_var('page')); $args = array_merge($args, foxyshop_sort_order_array()); query_posts($args); echo '<ul class="foxyshop_product_list">'; while (have_posts()) { the_post(); //Product Display foxyshop_include('product-loop'); } echo '</ul>'; //Pagination foxyshop_get_pagination(); ?> </div> <?php foxyshop_include('footer'); ?>