/** @see WP_Widget */ function widget($args, $instance) { extract($args); if (!is_tax('product_brand')) { return; } if (!get_query_var('term')) { return; } $thumbnail = ''; $term = get_term_by('slug', get_query_var('term'), 'product_brand'); $thumbnail = get_brand_thumbnail_url($term->term_id, 'large'); echo $before_widget . $before_title . $term->name . $after_title; woocommerce_get_template('widgets/brand-description.php', array('thumbnail' => $thumbnail), 'woocommerce-brands', untrailingslashit(plugin_dir_path(dirname(dirname(__FILE__)))) . '/templates/'); echo $after_widget; }
function woo_ce_get_product_brands($args = array()) { $term_taxonomy = apply_filters('woo_ce_brand_term_taxonomy', 'product_brand'); $defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0); $args = wp_parse_args($args, $defaults); $brands = get_terms($term_taxonomy, $args); if (!empty($brands) && is_wp_error($brands) == false) { foreach ($brands as $key => $brand) { $brands[$key]->description = woo_ce_format_description_excerpt($brand->description); $brands[$key]->parent_name = ''; if ($brands[$key]->parent_id = $brand->parent) { if ($parent_brand = get_term($brands[$key]->parent_id, $term_taxonomy)) { $brands[$key]->parent_name = $parent_brand->name; } unset($parent_brand); } else { $brands[$key]->parent_id = ''; } $brands[$key]->image = function_exists('get_brand_thumbnail_url') ? get_brand_thumbnail_url($brand->term_id) : false; } return $brands; } }
/** * output_product_brand function. * * @access public */ function output_product_brand($atts) { global $post; if (!$post) { return; } extract(shortcode_atts(array('width' => '', 'height' => '', 'class' => 'aligncenter'), $atts)); $brands = wp_get_post_terms($post->ID, 'product_brand', array("fields" => "ids")); if ($brands) { $brand = $brands[0]; } if (!empty($brand)) { $thumbnail = get_brand_thumbnail_url($brand); if ($thumbnail) { $term = get_term_by('id', $brand, 'product_brand'); if ($width || $height) { $width = $width ? $width : 'auto'; $height = $height ? $height : 'auto'; } ob_start(); woocommerce_get_template('shortcodes/single-brand.php', array('term' => $term, 'width' => $width, 'height' => $height, 'thumbnail' => $thumbnail, 'class' => $class), 'woocommerce-brands', untrailingslashit(plugin_dir_path(dirname(__FILE__))) . '/templates/'); return ob_get_clean(); } } }
<?php /** * Show a grid of thumbnails */ ?> <ul class="brand-thumbnails"> <?php foreach ($brands as $index => $brand) { $thumbnail = get_brand_thumbnail_url($brand->term_id, 'brand-thumb'); if (!$thumbnail) { $thumbnail = woocommerce_placeholder_img_src(); } $class = ''; if ($index == 0 || $index % $columns == 0) { $class = 'first'; } elseif (($index + 1) % $columns == 0) { $class = 'last'; } $width = floor((100 - ($columns - 1) * 2) / $columns * 100) / 100; ?> <li class="<?php echo $class; ?> " style="width: <?php echo $width; ?> %;"> <a href="<?php echo get_term_link($brand->slug, 'product_brand');