public function list_post_html($args, $instance, WP_Query $query)
    {
        $post_type = $this->get_post_type_from_instance($instance);
        $post_types = array();
        foreach ($post_type as $fvdata) {
            $ptvalue = isset($fvdata['value']) ? $fvdata['value'] : '';
            if (!empty($ptvalue)) {
                $post_types[] = $ptvalue;
            }
        }
        $full_width_post = hocwp_get_value_by_key($instance, 'full_width_post', $this->args['full_width_post']);
        $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail'));
        $thumbnail_size = isset($instance['thumbnail_size']) ? $instance['thumbnail_size'] : $this->args['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length'];
        $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length'));
        $list_class = 'list-unstyled';
        foreach ($post_types as $ptvalue) {
            hocwp_add_string_with_space_before($list_class, 'list-' . $ptvalue . 's');
        }
        $list_class = apply_filters('hocwp_widget_post_list_class', $list_class, $args, $instance, $this);
        $widget_html = '<ul class="' . $list_class . '">';
        $loop_html = apply_filters('hocwp_widget_post_loop_html', '', $args, $instance, $this);
        if (empty($loop_html)) {
            $count = 0;
            ob_start();
            while ($query->have_posts()) {
                $query->the_post();
                $post_id = get_the_ID();
                $post = get_post($post_id);
                $class = 'a-widget-post';
                $full_width = false;
                if ('all' == $full_width_post) {
                    $full_width = true;
                } elseif ('first' == $full_width_post && 0 == $count) {
                    $full_width = true;
                } elseif ('last' == $full_width_post && $count == $query->post_count) {
                    $full_width = true;
                } elseif ('first_last' == $full_width_post && (0 == $count || $count == $query->post_count)) {
                    $full_width = true;
                } elseif ('odd' == $full_width_post && $count % 2 != 0) {
                    $full_width = true;
                } elseif ('even' == $full_width_post && $count % 2 == 0) {
                    $full_width = true;
                }
                if ($full_width) {
                    hocwp_add_string_with_space_before($class, 'full-width');
                }
                if ($hide_thumbnail) {
                    hocwp_add_string_with_space_before($class, 'hide-thumbnail');
                }
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_add_string_with_space_before($class, 'show-excerpt');
                } else {
                    hocwp_add_string_with_space_before($class, 'hide-excerpt');
                }
                ?>
				<li <?php 
                post_class($class);
                ?>
>
					<?php 
                do_action('hocwp_widget_post_before_post', $args, $instance, $this);
                if (!(bool) $hide_thumbnail) {
                    if ('coupon' == $post->post_type) {
                        echo '<div class="text-center code-data">';
                        $percent = hocwp_get_coupon_percent_label($post_id);
                        $text = hocwp_get_coupon_text_label($post_id);
                        $type_text = 'Website Coupons';
                        $type_term = hocwp_get_coupon_type_term($post_id);
                        if (is_a($type_term, 'WP_Term')) {
                            $type_text = $type_term->name;
                        }
                        $tmp = hocwp_get_coupon_type($post_id);
                        if (is_array($tmp)) {
                            $tmp = array_shift($tmp);
                            if (!empty($tmp)) {
                                $type_text = $tmp;
                            }
                        }
                        $price = hocwp_get_post_meta('price', $post_id);
                        $sale_price = hocwp_get_post_meta('sale_price', $post_id);
                        if (!empty($price) && !empty($sale_price) || empty($percent)) {
                            $percentage = hocwp_percentage($price, $sale_price);
                            $percent = $percentage . '%';
                            $text = 'OFF';
                        }
                        ?>
							<div class="txt"><?php 
                        echo $percent . ' ' . $text;
                        ?>
</div>
							<div class="type"><?php 
                        echo $type_text;
                        ?>
</div>
							<?php 
                        echo '</div>';
                    } else {
                        $thumbnail_args = array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]);
                        if ($full_width) {
                            unset($thumbnail_args['width']);
                            unset($thumbnail_args['height']);
                        }
                        hocwp_post_thumbnail($thumbnail_args);
                    }
                }
                do_action('hocwp_widget_post_before_post_title', $args, $instance, $this);
                hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length)));
                do_action('hocwp_widget_post_after_post_title', $args, $instance, $this);
                if (0 < $excerpt_length) {
                    $post_type = get_post_type($post_id);
                    if ('product' == $post_type && hocwp_wc_installed()) {
                        hocwp_wc_product_price(null, true);
                    } else {
                        hocwp_entry_summary($excerpt_length);
                    }
                }
                do_action('hocwp_widget_post_after_post', $args, $instance, $this);
                ?>
				</li>
				<?php 
                $count++;
            }
            wp_reset_postdata();
            $loop_html .= ob_get_clean();
        }
        $widget_html .= $loop_html;
        $widget_html .= '</ul>';
        return $widget_html;
    }
Exemplo n.º 2
0
function hocwp_wc_sale_flash_filter($html, $post, $product)
{
    $use = (bool) get_option('hocwp_product_percentage_sale_flash');
    $use = apply_filters('hocwp_wc_product_percentage_sale_flash', $use, $post, $product);
    if ($use && hocwp_wc_is_sale($product->id) && hocwp_is_positive_number($product->sale_price)) {
        $html = '<span class="onsale">-' . hocwp_percentage($product->regular_price, $product->sale_price) . '%</span>';
    }
    $html = apply_filters('hocwp_wc_sale_flash', $html, $post, $product);
    return $html;
}