コード例 #1
0
function hocwp_option_home_setting_defaults()
{
    $alls = hocwp_option_defaults();
    $defaults = hocwp_get_value_by_key($alls, 'home_setting');
    if (!hocwp_array_has_value($defaults)) {
        $defaults = array('recent_posts' => 1, 'posts_per_page' => hocwp_get_posts_per_page(), 'pagination' => 1);
    }
    return apply_filters('hocwp_option_home_setting_defaults', $defaults);
}
コード例 #2
0
function hocwp_get_search_tracking($args = array())
{
    $defaults = array('orderby' => 'count', 'order' => 'desc', 'offset' => 0, 'posts_per_page' => hocwp_get_posts_per_page());
    $args = wp_parse_args($args, $defaults);
    $orderby = $args['orderby'];
    $order = $args['order'];
    $offset = $args['offset'];
    $posts_per_page = $args['posts_per_page'];
    global $wpdb;
    $table_name = $wpdb->prefix . HOCWP_SEARCH_TRACKING_TABLE;
    $sql = "SELECT * FROM {$table_name}";
    $sql .= " GROUP BY {$orderby} ORDER BY {$orderby} {$order} LIMIT {$posts_per_page} OFFSET {$offset}";
    $result = $wpdb->get_results($sql);
    return $result;
}
コード例 #3
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);
}
コード例 #4
0
ファイル: shop.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_get_product_posts_per_page()
{
    $number = get_option('hocwp_product_posts_per_page');
    if (!hocwp_is_positive_number($number)) {
        $reading = get_option('hocwp_reading');
        $number = hocwp_get_value_by_key($reading, 'products_per_page', hocwp_get_posts_per_page());
    }
    $number = apply_filters('hocwp_product_posts_per_page', $number);
    return $number;
}
コード例 #5
0
function hocwp_term_pagination($args = array())
{
    $query_vars = hocwp_get_value_by_key($args, 'query_vars', array());
    $posts_per_page = hocwp_get_value_by_key($query_vars, 'number', hocwp_get_posts_per_page());
    $offset = absint(hocwp_get_value_by_key($query_vars, 'offset'));
    $paged = hocwp_get_paged();
    $taxonomy = hocwp_get_value_by_key($args, 'taxonomy', 'category');
    if ($paged > 1) {
        $offset = ($paged - 1) * $posts_per_page;
    }
    $term_args = array('number' => 0, 'hide_empty' => false);
    $terms = hocwp_get_terms($taxonomy, $term_args);
    $total_page = 1;
    if (0 < $posts_per_page) {
        $total_page = ceil(count($terms) / $posts_per_page);
    }
    $args['current_page'] = $paged;
    $args['total_page'] = $total_page;
    $class = hocwp_get_value_by_key($args, 'class');
    hocwp_add_string_with_space_before($class, 'term-pagination');
    $args['class'] = $class;
    $result = hocwp_build_pagination($args);
    hocwp_pagination_before($args);
    echo $result;
    hocwp_pagination_after();
}
コード例 #6
0
ファイル: query.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_query_related_post($args = array())
{
    $post_id = absint(isset($args['post_id']) ? $args['post_id'] : get_the_ID());
    if ($post_id < 1) {
        return new WP_Query();
    }
    $current_post = get_post($post_id);
    if (!isset($args['post_type'])) {
        $args['post_type'] = $current_post->post_type;
    }
    $keep_current = (bool) hocwp_get_value_by_key($args, 'keep_current');
    $posts_per_page = hocwp_get_value_by_key($args, 'posts_per_page', hocwp_get_posts_per_page());
    $transient_name = 'hocwp_cache_post_' . $post_id . '_related_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    $cache = isset($args['cache']) ? $args['cache'] : true;
    $query = new WP_Query();
    if (!$cache || $cache && false === ($query = get_transient($transient_name))) {
        $taxonomies = get_post_taxonomies($post_id);
        $defaults = array();
        foreach ($taxonomies as $taxonomy) {
            $tax = get_taxonomy($taxonomy);
            if ((bool) $tax->hierarchical) {
                continue;
            }
            $term_ids = wp_get_post_terms($post_id, $taxonomies, array('fields' => 'ids'));
            if (hocwp_array_has_value($term_ids)) {
                $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids);
                $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults);
            }
        }
        if (hocwp_array_has_value($defaults)) {
            if (!$keep_current) {
                $defaults['post__not_in'] = array($post_id);
            }
            $defaults['tax_query']['relation'] = 'OR';
            $query_args = wp_parse_args($args, $defaults);
            $query = hocwp_query($query_args);
        }
        if (!is_a($query, 'WP_Query')) {
            $query = new WP_Query();
        }
        if ($query->post_count < $posts_per_page) {
            $missing = $posts_per_page - $query->post_count;
            $defaults = array();
            foreach ($taxonomies as $taxonomy) {
                $tax = get_taxonomy($taxonomy);
                if (!(bool) $tax->hierarchical) {
                    continue;
                }
                $term_ids = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'ids'));
                if (hocwp_array_has_value($term_ids)) {
                    $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids);
                    $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults);
                }
            }
            if (!$keep_current) {
                $defaults['post__not_in'] = array($post_id);
            }
            $defaults['tax_query']['relation'] = 'OR';
            $defaults['posts_per_page'] = $missing;
            unset($args['tax_query']);
            $args = wp_parse_args($args, $defaults);
            $cat_query = hocwp_query($args);
            $post_ids = array();
            if (hocwp_array_has_value($query->posts)) {
                foreach ($query->posts as $post) {
                    array_push($post_ids, $post->ID);
                }
            }
            if (hocwp_array_has_value($cat_query->posts)) {
                foreach ($cat_query->posts as $post) {
                    array_push($post_ids, $post->ID);
                }
            }
            $args['posts_per_page'] = $posts_per_page;
            $args['post__in'] = $post_ids;
            $args['orderby'] = 'post__in';
            $query = hocwp_query($args);
        }
        if (!$query->have_posts()) {
            unset($args['post__in']);
            unset($args['tax_query']);
            $args['orderby'] = 'date';
            $args['s'] = $current_post->post_title;
            $query = hocwp_query($args);
        }
        $cache_days = apply_filters('hocwp_related_post_cache_days', 3);
        if (!$query->have_posts()) {
            $cache_days = 1;
        }
        if (($cache || hocwp_is_positive_number($cache)) && $query->have_posts()) {
            if (!hocwp_is_positive_number($cache)) {
                $cache = $cache_days * DAY_IN_SECONDS;
            }
            set_transient($transient_name, $query, $cache);
        }
    }
    return $query;
}
コード例 #7
0
function hocwp_wc_product_settings_page($settings)
{
    $item = array('title' => __('Thumbnail on gallery', 'hocwp-theme'), 'desc' => __('Auto add current product thumbnail into it\'s gallery', 'hocwp-theme'), 'id' => 'hocwp_single_product_thumbnail_on_gallery', 'default' => 'no', 'type' => 'checkbox');
    hocwp_wc_add_settings_field($settings, $item, 'image_options');
    $item = array('title' => __('Thumbnail zooming', 'hocwp-theme'), 'desc' => __('Add function allow user can zoom current product image on single page', 'hocwp-theme'), 'id' => 'hocwp_single_product_thumbnail_zoom', 'default' => 'no', 'type' => 'checkbox');
    hocwp_wc_add_settings_field($settings, $item, 'image_options');
    $item = array('title' => __('Gallery on left', 'hocwp-theme'), 'desc' => __('Display gallery on the left of single product main image', 'hocwp-theme'), 'id' => 'hocwp_single_product_gallery_left', 'default' => 'no', 'type' => 'checkbox');
    hocwp_wc_add_settings_field($settings, $item, 'image_options');
    $item = array('title' => __('Gallery preview', 'hocwp-theme'), 'desc' => __('Auto show gallery image in current product thumbnail on mouse hover', 'hocwp-theme'), 'id' => 'hocwp_single_product_gallery_preview', 'default' => 'yes', 'type' => 'checkbox');
    hocwp_wc_add_settings_field($settings, $item, 'image_options');
    $item = array('title' => __('Additional Settings', 'hocwp-theme'), 'type' => 'title', 'desc' => __('You can change number products to show on archive page.', 'hocwp-theme'), 'id' => 'hocwp_additional_settings');
    hocwp_wc_add_settings_field($settings, $item, '');
    $item = array('title' => __('Posts per page', 'hocwp-theme'), 'id' => 'hocwp_product_posts_per_page', 'type' => 'number', 'custom_attributes' => array('min' => 1, 'step' => 1), 'css' => 'width: 80px;', 'default' => hocwp_get_posts_per_page(), 'autoload' => false);
    hocwp_wc_add_settings_field($settings, $item, 'hocwp_additional_settings');
    $item = array('title' => __('Percentage sale flash', 'hocwp-theme'), 'desc' => __('Display product sale flash as percentage instead of text', 'hocwp-theme'), 'id' => 'hocwp_product_percentage_sale_flash', 'default' => 'no', 'type' => 'checkbox');
    hocwp_wc_add_settings_field($settings, $item, 'hocwp_additional_settings');
    $item = array('type' => 'sectionend', 'id' => 'hocwp_additional_settings');
    hocwp_wc_add_settings_field($settings, $item, '');
    return $settings;
}