function widget($args, $instance) { global $mp; if ($instance['only_store_pages'] && !mp_is_shop_page()) { return; } extract($args); echo $before_widget; $title = $instance['title']; if (!empty($title)) { echo $before_title . apply_filters('widget_title', $title) . $after_title; } if (!empty($instance['custom_text'])) { echo '<div id="custom_text">' . $instance['custom_text'] . '</div>'; } /* setup our custom query */ //setup taxonomy if applicable if ($instance['taxonomy_type'] == 'category') { $taxonomy_query = '&product_category=' . $instance['taxonomy']; } else { if ($instance['taxonomy_type'] == 'tag') { $taxonomy_query = '&product_tag=' . $instance['taxonomy']; } else { $taxonomy_query = ''; } } //figure out perpage if (isset($instance['num_products']) && intval($instance['num_products']) > 0) { $paginate_query = '&posts_per_page=' . intval($instance['num_products']) . '&paged=1'; } else { $paginate_query = '&posts_per_page=10&paged=1'; } //get order by if ($instance['order_by']) { if ($instance['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price&orderby=meta_value_num'; } else { if ($instance['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $instance['order_by']; } } } else { $order_by_query = '&orderby=title'; } //get order direction if ($instance['order']) { $order_query = '&order=' . $instance['order']; } else { $order_query = '&orderby=DESC'; } //The Query $custom_query = new WP_Query('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //do we have products? if (count($custom_query->posts)) { echo '<ul id="mp_product_list" class="">'; foreach ($custom_query->posts as $post) { $btnclass = mpt_load_mp_btn_color(); echo '<li ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; echo '<div class="row-fluid">'; if ($instance['show_thumbnail']) { echo '<div class="span4">'; mp_product_image(true, 'widget', $post->ID, $instance['size']); echo '</div>'; echo '<div class="span8">'; } else { echo '<div class="span12">'; } echo '<p class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . esc_attr($post->post_title) . '</a></p>'; if ($instance['show_excerpt']) { echo '<div class="mp_product_content">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID) . '</div>'; } if ($instance['show_price'] || $instance['show_button']) { echo '<div class="mp_product_meta' . ($instance['show_excerpt'] ? ' align-right' : '') . '">'; if ($instance['show_price']) { echo flexmarket_product_price(false, $post->ID, '', '', 'widget'); } if ($instance['show_button']) { echo flexmarket_buy_button(false, 'list', $post->ID, $btnclass . ' btn-small'); } echo '</div>'; } echo '</div>'; //End span echo '</div>'; // End Row-fluid echo '</li>'; } echo '</ul>'; } else { ?> <div class="widget-error"> <?php _e('No Products', 'mp'); ?> </div> <?php } echo $after_widget; }
function mp_product($echo = true, $product_id, $title = true, $content = 'full', $image = 'single', $meta = true) { global $mp; if (function_exists('icl_object_id')) { $product_id = icl_object_id($product_id, 'product', false); } $post = get_post($product_id); $return = '<div itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; $return .= '<span style="display:none" class="date updated">' . get_the_time($product_id) . '</span>'; if ($title) { $return .= '<h3 itemprop="name" class="mp_product_name entry-title"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; } if ($content) { $return .= '<div itemprop="description" class="mp_product_content">'; if ($image) { $return .= mp_product_image(false, $image, $post->ID); } if ($content == 'excerpt') { $return .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } else { $return .= apply_filters('the_content', $post->post_content); } $return .= '</div>'; } if ($meta) { //price $return .= mp_product_price(false, $post->ID); //button $return .= mp_buy_button(false, 'single', $post->ID); } $return .= '</div>'; $return = apply_filters('mp_product', $return, $product_id, $title, $content, $image, $meta); if ($echo) { echo $return; } else { return $return; } }
function mp_list_products($echo = true, $paginate = '', $page = '', $per_page = '', $order_by = '', $order = '', $category = '', $tag = '') { global $wp_query, $mp; $settings = get_option('mp_settings'); //setup taxonomy if applicable if ($category) { $taxonomy_query = '&product_category=' . sanitize_title($category); } else { if ($tag) { $taxonomy_query = '&product_tag=' . sanitize_title($tag); } else { if ($wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag') { $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']); } } } //setup pagination $paged = false; if ($paginate) { $paged = true; } else { if ($paginate === '') { if ($settings['paginate']) { $paged = true; } else { $paginate_query = '&nopaging=true'; } } else { $paginate_query = '&nopaging=true'; } } //get page details if ($paged) { //figure out perpage if (intval($per_page)) { $paginate_query = '&posts_per_page=' . intval($per_page); } else { $paginate_query = '&posts_per_page=' . $settings['per_page']; } //figure out page if ($wp_query->query_vars['paged']) { $paginate_query .= '&paged=' . intval($wp_query->query_vars['paged']); } if (intval($page)) { $paginate_query .= '&paged=' . intval($page); } else { if ($wp_query->query_vars['paged']) { $paginate_query .= '&paged=' . intval($wp_query->query_vars['paged']); } } } //get order by if (!$order_by) { if ($settings['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ($settings['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $settings['order_by']; } } } else { if ('price' == $order_by) { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $order_by; } } //get order direction if (!$order) { $order_query = '&order=' . $settings['order']; } else { $order_query = '&order=' . $order; } //The Query $custom_query = new WP_Query('post_type=product&post_status=publish' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //allows pagination links to work get_posts_nav_link() if ($wp_query->max_num_pages == 0 || $taxonomy_query) { $wp_query->max_num_pages = $custom_query->max_num_pages; } $content = '<div id="mp_product_list">'; if ($last = count($custom_query->posts)) { $count = 1; foreach ($custom_query->posts as $post) { //add last css class for styling grids if ($count == $last) { $class = array('mp_product', 'last-product'); } else { $class = 'mp_product'; } $content .= '<div ' . mp_product_class(false, $class, $post->ID) . '>'; $content .= '<h3 class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; $content .= '<div class="mp_product_content">'; $product_content = mp_product_image(false, 'list', $post->ID); if ($settings['show_excerpt'] == 1) { $product_content .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } $content .= apply_filters('mp_product_list_content', $product_content, $post->ID); $content .= '</div>'; $content .= '<div class="mp_product_meta">'; //price $meta = mp_product_price(false, $post->ID); //button $meta .= mp_buy_button(false, 'list', $post->ID); $content .= apply_filters('mp_product_list_meta', $meta, $post->ID); $content .= '</div>'; $content .= '</div>'; $count++; } } else { $content .= '<div id="mp_no_products">' . apply_filters('mp_product_list_none', __('No Products', 'mp')) . '</div>'; } $content .= '</div>'; if ($echo) { echo $content; } else { return $content; } }
function _mp_global_products_html_list($results, $args) { global $mp, $post; $html = ''; $total = count($results); $count = 0; $current_blog_id = get_current_blog_id(); $current_post = $post; foreach ($results as $index => $result) { switch_to_blog($result->blog_id); $post = get_post($result->post_id); setup_postdata($post); $count = $index + 1; //add last css class for styling grids if ($count == $total) { $class = array('mp_product', 'last-product', 'hentry'); } else { $class = array('mp_product', 'hentry'); } $html .= ' <div itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, $class, $post->ID) . '> <h3 class="mp_product_name entry-title"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3> <div class="entry-content"> <div class="mp_product_content">'; $product_content = ''; if ($args['show_thumbnail']) { $product_content = mp_product_image(false, 'list', $post->ID, $args['thumbnail_size']); } if ($args['text'] == 'excerpt') { $product_content .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } elseif ($args['text'] == 'content') { $product_content .= get_the_content(); } $html .= apply_filters('mp_product_list_content', $product_content, $post->ID); $html .= mp_pinit_button($post->ID, 'all_view'); $html .= ' </div> <div class="mp_product_meta">'; $meta = ''; //price if ($args['show_price']) { $meta .= mp_product_price(false, $post->ID); } //button $meta .= '<a class="mp_link_buynow" href="' . get_permalink($post->ID) . '">' . __('Buy Now »', 'mp') . '</a>'; $html .= apply_filters('mp_product_list_meta', $meta, $post->ID); $html .= ' </div> </div> <div style="display:none"> <time class="updated">' . get_the_time('Y-m-d\\TG:i') . '</time> by <span class="author vcard"><span class="fn">' . get_the_author_meta('display_name') . '</span></span> </div> </div>'; } $post = $current_post; //wp_reset_postdata() doesn't work here switch_to_blog($current_blog_id); return apply_filters('_mp_global_products_html_list', $html, $results); }
function framemarket_grid_mp_list_products($echo = true, $paginate = '', $paged = '', $per_page = '', $order_by = '', $order = '', $category = '', $tag = '', $search = '') { global $wp_query, $mp, $grid_home; $settings = get_option('mp_settings'); //setup taxonomy if applicable $taxonomy_query = ''; if ($category) { $taxonomy_query = '&product_category=' . sanitize_title($category); } else { if ($tag) { $taxonomy_query = '&product_tag=' . sanitize_title($tag); } else { if (isset($wp_query->query_vars['taxonomy']) && ($wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag')) { $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']); } } } //check if it's a search $search_query = ''; if (isset($wp_query->query_vars['s']) && $wp_query->query_vars['s']) { $search_query = '&s=' . $wp_query->query_vars['s']; } if ($paginate) { // $paged = true; } else { if ($paginate === '') { if ($settings['paginate']) { //$paged = true; } else { $paginate_query = '&nopaging=true'; } } else { $paginate_query = '&nopaging=true'; } } if (!$paged) { $paged = $wp_query->query_vars['paged'] ? $wp_query->query_vars['paged'] : 1; } //get page details if ($paged) { //figure out perpage if (intval($per_page)) { $paginate_query = '&posts_per_page=' . intval($per_page); } else { $paginate_query = '&posts_per_page=' . $settings['per_page']; } //figure out page //if ( $wp_query->query_vars['paged'] ) // $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']); if (intval($paged)) { $paginate_query .= '&paged=' . intval($paged); } else { if ($wp_query->query_vars['paged']) { $paginate_query .= '&paged=' . intval($wp_query->query_vars['paged']); } } /*else if ($paged) $paginate_query .= '&paged='.intval($paged);*/ } //get order by if (!$order_by) { if ($settings['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ($settings['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $settings['order_by']; } } } else { if ('price' == $order_by) { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ('sales' == $order_by) { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $order_by; } } } //get order direction if (!$order) { $order_query = '&order=' . $settings['order']; } else { $order_query = '&order=' . $order; } //The Query $custom_query = new WP_Query('post_type=product&post_status=publish' . $search_query . $taxonomy_query . $paginate_query . $order_by_query . $order_query); $wp_query = $custom_query; $content = '<div id="mp_product_list">'; if ($last = count($custom_query->posts)) { $count = 1; $counter = 0; foreach ($custom_query->posts as $post) { //add last css class for styling grids if ($count % 4 == 0) { $class = array('mp_product', 'last-product'); } else { $class = 'mp_product'; } $content .= '<div ' . mp_product_class(false, $class, $post->ID) . '>'; $content .= '<h3 class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; $content .= '<div class="mp_product_content">'; $product_content = mp_product_image(false, 'list', $post->ID); $product_content .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); $content .= apply_filters('mp_product_list_content', $product_content, $post->ID); $content .= '</div>'; $content .= '<div class="mp_product_meta">'; //price $meta = mp_product_price(false, $post->ID, false); //button $meta .= mp_buy_button(false, 'list', $post->ID); $content .= apply_filters('mp_product_list_meta', $meta, $post->ID); $content .= '</div>'; $content .= '</div>'; $count++; $counter++; //add last css class for styling grids if ($counter % 4 == 0) { $content .= '<div class="clear"></div>'; } } } else { $content .= '<div id="mp_no_products">' . apply_filters('mp_product_list_none', __('No Products', 'mp')) . '</div>'; } $content .= '</div>'; if ($wp_query->max_num_pages > 1) { $content .= '<div id="navigation-bottom" class="navigation">'; if ($wp_query->query_vars['paged'] > 1) { if ($grid_home) { $content .= '<div class="nav-previous"><a href="?page=' . ($wp_query->query_vars['paged'] - 1) . '" >' . __('<span class="meta-nav">←</span> Previous', 'framemarket') . '</a></div>'; } else { $content .= '<div class="nav-previous">' . get_previous_posts_link(__('<span class="meta-nav">←</span> Previous', 'framemarket')) . '</a></div>'; } } if ($wp_query->max_num_pages > $wp_query->query_vars['paged']) { if ($grid_home) { $content .= '<div class="nav-next"><a href="?page=' . ($wp_query->query_vars['paged'] + 1) . '" >' . __('Next <span class="meta-nav">→</span>', 'framemarket') . '</a></div>'; } else { $content .= '<div class="nav-next">' . get_next_posts_link(__('Next <span class="meta-nav">→</span>', 'framemarket')) . '</div>'; } } $content .= '</div>'; } if ($echo) { echo $content; } else { return $content; } }
function widget($args, $instance) { global $mp, $post; if ($instance['only_store_pages'] && !mp_is_shop_page()) { return; } extract($args); echo $before_widget; $title = $instance['title']; if (!empty($title)) { echo $before_title . apply_filters('widget_title', $title) . $after_title; } if (!empty($instance['custom_text'])) { echo '<div id="custom_text">' . $instance['custom_text'] . '</div>'; } /* setup our custom query */ //setup taxonomy if applicable if ($instance['taxonomy_type'] == 'category') { $taxonomy_query = '&product_category=' . $instance['taxonomy']; } else { if ($instance['taxonomy_type'] == 'tag') { $taxonomy_query = '&product_tag=' . $instance['taxonomy']; } else { $taxonomy_query = ''; } } //figure out perpage if (isset($instance['num_products']) && intval($instance['num_products']) > 0) { $paginate_query = '&posts_per_page=' . intval($instance['num_products']) . '&paged=1'; } else { $paginate_query = '&posts_per_page=10&paged=1'; } //get order by if ($instance['order_by']) { if ($instance['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ($instance['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $instance['order_by']; } } } else { $order_by_query = '&orderby=title'; } //get order direction if ($instance['order']) { $order_query = '&order=' . $instance['order']; } else { $order_query = '&orderby=DESC'; } //The Query $custom_query = new WP_Query('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //do we have products? if ($custom_query->have_posts()) { echo '<ul id="mp_product_list" class="hfeed">'; while ($custom_query->have_posts()) { $custom_query->the_post(); echo '<li itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, array('mp_product', 'hentry'), $post->ID) . '>'; echo '<h3 class="mp_product_name entry-title" itemprop="name"><a href="' . get_permalink($post->ID) . '">' . esc_attr($post->post_title) . '</a></h3>'; if ($instance['show_thumbnail']) { mp_product_image(true, 'widget', $post->ID, $instance['size']); } echo '<div class="entry-content" style="margin:0;padding:0;width:auto;">'; if ($instance['show_excerpt']) { echo '<div class="mp_product_content">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID) . '</div>'; } if ($instance['show_price'] || $instance['show_button']) { echo '<div class="mp_product_meta">'; if ($instance['show_price']) { echo mp_product_price(false, $post->ID, ''); } if ($instance['show_button']) { echo mp_buy_button(false, 'list', $post->ID); } echo '</div>'; } echo '</div>'; echo '<div style="display:none"> <time class="updated">' . get_the_time('Y-m-d\\TG:i') . '</time> by <span class="author vcard"><span class="fn">' . get_the_author_meta('display_name') . '</span></span> </div>'; echo '</li>'; } wp_reset_postdata(); echo '</ul>'; } else { ?> <div class="widget-error"> <?php _e('No Products', 'mp'); ?> </div> <?php } echo $after_widget; }
function mp_product($echo = true, $product_id, $title = true, $content = 'full', $image = 'single', $meta = true) { global $mp; $post = get_post($product_id); $return = '<div itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; if ($title) { $return .= '<h3 itemprop="name" class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; } if ($content) { $return .= '<div itemprop="description" class="mp_product_content">'; if ($image) { $return .= mp_product_image(false, $image, $post->ID); } if ($content == 'excerpt') { $return .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } else { $return .= apply_filters('the_content', $post->post_content); } $return .= '</div>'; } if ($meta) { $return .= '<div itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="mp_product_meta">'; //price $return .= mp_product_price(false, $post->ID); //button $return .= mp_buy_button(false, 'single', $post->ID); $return .= '</div>'; } $return .= '</div>'; if ($echo) { echo $return; } else { return $return; } }