Example #1
0
function hocwp_shortcode_post_callback($atts = array(), $content = null)
{
    $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => '');
    $attributes = shortcode_atts($defaults, $atts);
    $transient_name = 'hocwp_shortcode_post_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $attributes);
    if (false === ($html = get_transient($transient_name))) {
        $order = $attributes['order'];
        $orderby = $attributes['orderby'];
        $by = $attributes['by'];
        $post_type = hocwp_string_to_array(',', $attributes['post_type']);
        $post_type = array_map('trim', $post_type);
        $offset = $attributes['offset'];
        $column = $attributes['column'];
        if (!hocwp_is_positive_number($column)) {
            $column = 1;
        }
        $number = $attributes['number'];
        $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column);
        $exclude_current = (bool) $attributes['exclude_current'];
        $display = $attributes['display'];
        $display = trim($display);
        $excerpt_length = $attributes['excerpt_length'];
        $post = $attributes['post'];
        $post = hocwp_find_post($post);
        $posts = $attributes['posts'];
        $posts = hocwp_string_to_array(',', $posts);
        $thumbnail_size = $attributes['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $interval = $attributes['interval'];
        if (hocwp_is_post($post)) {
            $display = 'full';
        }
        $class = 'hocwp-shortcode-post';
        hocwp_add_string_with_space_before($class, $order);
        hocwp_add_string_with_space_before($class, $by);
        hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display));
        if ('100%' == $display) {
            $class = hocwp_add_more_class($class, 'full-width');
        }
        hocwp_add_string_with_space_before($class, implode(' ', $post_type));
        $query = null;
        if (!hocwp_is_post($post)) {
            $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby);
            if (!empty($interval)) {
                hocwp_query_sanitize_date_query_args($interval, $args);
            }
            if ($exclude_current && is_singular()) {
                $post_id = get_the_ID();
                $args['post__not_in'] = array($post_id);
            }
            if (hocwp_array_has_value($posts)) {
                $args['post__in'] = $posts;
            }
            $query = hocwp_query_by($by, $args);
        } else {
            if (!hocwp_is_positive_number($excerpt_length)) {
                $excerpt_length = 200;
            }
        }
        if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) {
            $html = hocwp_shortcode_before($class, $attributes);
            $width = $thumbnail_size[0];
            if (hocwp_is_post($post)) {
                global $post;
                setup_postdata($post);
                ob_start();
                ?>
				<div class="one-post">
					<div <?php 
                post_class('', $post);
                ?>
>
						<?php 
                if ($width > 0) {
                    hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID));
                }
                hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post)));
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_entry_summary($excerpt_length);
                }
                ?>
					</div>
				</div>
				<?php 
                $html .= ob_get_clean();
                wp_reset_postdata();
            } else {
                $html .= '<div class="in-loop row-small">';
                $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes);
                if (empty($loop)) {
                    $count = 1;
                    $style = '';
                    if ('left' != $display && 'right' != $display) {
                        $style = 'width:' . hocwp_column_width_percentage($column);
                    }
                    while ($query->have_posts()) {
                        $query->the_post();
                        $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes);
                        if (empty($html_loop)) {
                            $item_class = 'item';
                            if (hocwp_is_last_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'last-item');
                            } elseif (hocwp_is_first_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'first-item');
                            }
                            ob_start();
                            ?>
							<div class="<?php 
                            echo $item_class;
                            ?>
" style="<?php 
                            echo $style;
                            ?>
">
								<div <?php 
                            post_class();
                            ?>
>
									<?php 
                            if ($width > 0) {
                                hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]));
                            }
                            hocwp_post_title_link();
                            if (hocwp_is_positive_number($excerpt_length)) {
                                hocwp_entry_summary($excerpt_length);
                            }
                            ?>
								</div>
							</div>
							<?php 
                            $html_loop = ob_get_clean();
                        }
                        $loop .= $html_loop;
                        $count++;
                    }
                    wp_reset_postdata();
                }
                $html .= $loop;
                $html .= '</div>';
            }
            $html .= hocwp_shortcode_after();
        } else {
            $html = '';
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, WEEK_IN_SECONDS);
        }
    }
    return apply_filters('hocwp_shortcode_post', $html, $attributes, $content);
}
Example #2
0
<?php

hocwp_article_before();
hocwp_post_thumbnail(array('width' => 200, 'height' => 120));
hocwp_post_title_link();
hocwp_entry_meta();
hocwp_entry_summary(250);
hocwp_article_after();
    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;
    }
Example #4
0
function hocwp_article_header($args = array())
{
    $loop = isset($args['loop']) ? $args['loop'] : false;
    $entry_meta = isset($args['entry_meta']) ? $args['entry_meta'] : true;
    ?>
	<header class="entry-header">
		<?php 
    if (!$loop && (is_single() || is_singular())) {
        hocwp_post_title_single();
    } else {
        hocwp_post_title_link();
    }
    if (!is_page() && $entry_meta) {
        ?>
			<div class="entry-meta">
				<?php 
        hocwp_entry_meta();
        ?>
			</div><!-- .entry-meta -->
			<?php 
    }
    ?>
	</header><!-- .entry-header -->
	<?php 
}
function hocwp_wc_get_cart_preview_html()
{
    $cart_preview = '';
    $cart_items = hocwp_wc_get_cart_items();
    $cart_preview .= '<ul class="cart-preview list-unstyled">';
    $cart_preview .= '<li class="title">' . __('Your cart', 'hocwp-theme') . '</li>';
    if (hocwp_array_has_value($cart_items)) {
        $cart_preview .= '<li class="cart-items"><ul class="list-unstyled list-products">';
        foreach ($cart_items as $item) {
            $post_id = hocwp_get_value_by_key($item, 'product_id');
            if (!hocwp_id_number_valid($post_id)) {
                continue;
            }
            $quantity = absint(hocwp_get_value_by_key($item, 'quantity'));
            $data = hocwp_get_value_by_key($item, 'data');
            $data = hocwp_object_to_array($data);
            $price = floatval(hocwp_get_value_by_key($data, 'price'));
            $li = new HOCWP_HTML('li');
            $li->set_class(hocwp_get_post_class($post_id, 'clearfix'));
            ob_start();
            hocwp_post_thumbnail(array('width' => 44, 'height' => 44, 'post_id' => $post_id));
            hocwp_post_title_link(array('title' => get_the_title($post_id), 'permalink' => get_permalink($post_id)));
            echo '<p class="info">';
            echo '<span class="price">' . sprintf(__('Price: %s', 'hocwp-theme'), hocwp_wc_format_price($price)) . '</span>';
            echo '<span class="quantity">' . sprintf(__('Quantity: %s', 'hocwp-theme'), number_format($quantity)) . '</span>';
            echo '</p>';
            echo '<i class="fa fa-remove" data-id="' . $post_id . '"></i>';
            $li_html = ob_get_clean();
            $li->set_text($li_html);
            $cart_preview .= $li->build();
        }
        $cart_preview .= '</ul></li>';
        $cart_preview .= '<li class="bottom">';
        $cart_preview .= '<span class="total">' . __('Total', 'hocwp-theme') . ': <strong>' . hocwp_wc_get_cart_total_formatted() . '</strong></span>';
        $cart_preview .= '<a class="btn-clickable orange go-page" href="' . hocwp_wc_get_checkout_url() . '">' . __('Checkout', 'hocwp-theme') . '</a>';
        $cart_preview .= '</li>';
    } else {
        $cart_preview .= '<li class="no-item-message">' . __('Your cart is empty now.', 'hocwp-theme') . '</li>';
    }
    $cart_preview .= '</ul>';
    $cart_preview = apply_filters('hocwp_wc_cart_preview_html', $cart_preview);
    return $cart_preview;
}