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); }
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; }
<?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();
function hocwp_wc_single_product_fast_buy_button($args = array()) { $use = hocwp_wc_use_fast_buy_button(); if ($use) { global $product; $backup = $product; $post_id = hocwp_get_value_by_key($args, 'post_id'); $post_id = hocwp_return_post($post_id, 'id'); $tmp = new WC_Product($product); $product = $tmp; $show_button = (bool) hocwp_get_value_by_key($args, 'show_button', true); hocwp_div_clear(); do_action('hocwp_wc_before_fast_buy_button'); if ($show_button) { $args['post_id'] = $post_id; hocwp_wc_product_fast_buy_button($args); } ?> <div id="productBuy<?php echo $post_id; ?> " role="dialog" tabindex="-1" class="modal fade product-fast-buy"> <div class="modal-dialog"> <div class="modal-content clearfix"> <div class="modal-header"> <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span></button> <h4 class="modal-title"><?php _e('Fast order', 'hocwp-theme'); ?> </h4> </div> <div class="modal-body"> <div class="row row-medium"> <div class="col-xs-12 col-md-6 info-column"> <div class="product-info"> <?php hocwp_post_thumbnail(array('bfi_thumb' => false, 'loop' => false)); hocwp_post_title_single(array('tag' => 'h2')); $get_variations = sizeof($product->get_children()) <= apply_filters('woocommerce_ajax_variation_threshold', 30, $product); $attributes = array(); if (hocwp_wc_is_variable($product)) { $tmp = new WC_Product_Variable($product); $product = $tmp; $attributes = $product->get_variation_attributes(); } $attribute_keys = array_keys($attributes); //$selected_attributes = $product->get_variation_default_attributes(); $available_variations = false; if (hocwp_wc_is_variable($product)) { $available_variations = $get_variations ? $product->get_available_variations() : false; } if (empty($available_variations) && false !== $available_variations) { ?> <p class="stock out-of-stock"><?php _e('This product is currently out of stock and unavailable.', 'hocwp-theme'); ?> </p> <?php } else { ?> <?php if (hocwp_array_has_value($attributes)) { ?> <form class="variations_form cart attributes-form" method="post"> <table class="variations" cellspacing="0"> <tbody> <?php foreach ($attributes as $attribute_name => $options) { ?> <tr> <td class="label"><label for="<?php echo sanitize_title($attribute_name); ?> "><?php echo wc_attribute_label($attribute_name); ?> </label> </td> <td class="value"> <?php $selected = isset($_REQUEST['attribute_' . sanitize_title($attribute_name)]) ? wc_clean($_REQUEST['attribute_' . sanitize_title($attribute_name)]) : $product->get_variation_default_attribute($attribute_name); wc_dropdown_variation_attribute_options(array('options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected)); echo end($attribute_keys) === $attribute_name ? apply_filters('woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __('Clear', 'hocwp-theme') . '</a>') : ''; ?> </td> </tr> <?php } ?> </tbody> </table> </form> <?php } ?> <?php } hocwp_wc_product_price(null, true); ?> </div> </div> <div class="col-xs-12 col-md-6 customer-column"> <div class="customer-info"> <?php $name = ''; $email = ''; $phone = ''; $address = ''; if (is_user_logged_in()) { $current = wp_get_current_user(); $name = get_user_meta($current->ID, 'billing_first_name', true); $last_name = get_user_meta($current->ID, 'billing_last_name', true); if (!empty($last_name)) { $name = $last_name . ' ' . $name; } $name = trim($name); if (empty($name)) { $name = $current->display_name; } $email = get_user_meta($current->ID, 'billing_email', true); if (!is_email($email)) { $email = $current->user_email; } $phone = get_user_meta($current->ID, 'billing_phone', true); $address = get_user_meta($current->ID, 'billing_address_1', true); } ?> <form class="order-form" method="post"> <div class="form-group"> <p><?php echo sprintf(__('Required fields are marked as %s', 'hocwp-theme'), HOCWP_REQUIRED_HTML); ?> </p> </div> <div class="form-group"> <input type="text" required aria-required="true" value="<?php echo $name; ?> " class="full-name form-control" placeholder="<?php _e('Full name *', 'hocwp-theme'); ?> " name="fullname"> </div> <div class="form-group"> <input type="text" class="phone form-control" value="<?php echo $phone; ?> " placeholder="<?php _e('Phone', 'hocwp-theme'); ?> " name="phone"> </div> <div class="form-group"> <input type="text" required aria-required="true" value="<?php echo $email; ?> " class="email form-control" placeholder="<?php _e('Email *', 'hocwp-theme'); ?> " name="email"> </div> <div class="form-group"> <input type="text" class="address form-control" value="<?php echo $address; ?> " placeholder="<?php _e('Address', 'hocwp-theme'); ?> " name="address"> </div> <div class="form-group"> <label for="message"><?php _e('Note:', 'hocwp-theme'); ?> </label> <textarea id="message" name="message" class="message form-control"></textarea> </div> <div class="form-group"> <button class="btn-clickable orange" data-id="<?php echo $post_id; ?> "> <span><?php _e('Put order', 'hocwp-theme'); ?> </span> </button> </div> </form> </div> </div> </div> </div> </div> </div> </div> <?php $product = $backup; } }