<div class="<?php hocwp_wrap_class(); ?> "> <?php hocwp_breadcrumb(); hocwp_theme_site_main_before(); hocwp_article_before(); hocwp_post_title_single(); hocwp_entry_meta(); hocwp_entry_content(); hocwp_addthis_toolbox(); hocwp_comments_template(); hocwp_entry_tags(); $args = array('posts_per_page' => 5, 'post_type' => 'post'); $query = hocwp_query_related_post($args); if ($query->have_posts()) { ?> <div class="module related"> <div class="module-header cross"> <h3><?php _e('Related Posts', 'hocwp-theme'); ?> </h3> </div> <div class="module-body"> <?php echo '<div class="loop-posts">'; while ($query->have_posts()) { $query->the_post(); hocwp_theme_get_loop('post');
public function widget($args, $instance) { $this->instance = $instance; global $post; $title = hocwp_widget_title($args, $instance, false); $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; } } $number = isset($instance['number']) ? $instance['number'] : $this->args['number']; $by = isset($instance['by']) ? $instance['by'] : $this->args['by']; $category = isset($instance['category']) ? $instance['category'] : json_encode($this->args['category']); $category = hocwp_json_string_to_array($category); $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length']; $content_class = 'widget-content'; $slider = hocwp_get_value_by_key($instance, 'slider', hocwp_get_value_by_key($this->args, 'slider')); $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length')); $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail')); $widget_title_link_category = hocwp_get_value_by_key($instance, 'widget_title_link_category', hocwp_get_value_by_key($this->args, 'widget_title_link_category')); $category_as_widget_title = hocwp_get_value_by_key($instance, 'category_as_widget_title', hocwp_get_value_by_key($this->args, 'category_as_widget_title')); if ((bool) $slider) { hocwp_add_string_with_space_before($content_class, 'post-slider'); } if ('category' == $by && (bool) $widget_title_link_category) { $cvalue = current($category); $term_id = isset($cvalue['value']) ? $cvalue['value'] : ''; $term_id = absint($term_id); if ($term_id > 0) { $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : ''; $link = new HOCWP_HTML('a'); $link->set_class('term-link'); $link->set_href(get_term_link($term_id, $taxonomy)); if ((bool) $category_as_widget_title) { $term = get_term($term_id, $taxonomy); $title = $term->name; } else { $title = hocwp_get_value_by_key($instance, 'title'); } $link->set_text($title); $title = hocwp_get_value_by_key($args, 'before_title') . $link->build() . hocwp_get_value_by_key($args, 'after_title'); } } $query_args = array('posts_per_page' => $number, 'post_type' => $post_types); $w_query = new WP_Query(); $get_by = false; switch ($by) { case 'recent': $get_by = true; break; case 'modified': case 'recent_modified': $get_by = true; $query_args['orderby'] = 'modified'; $query_args['order'] = 'DESC'; break; case 'rand': case 'random': $get_by = true; $query_args['orderby'] = 'rand'; break; case 'most_comment': case 'comment_count': case 'comment': $get_by = true; $query_args['orderby'] = 'comment_count'; break; case 'category': foreach ($category as $cvalue) { $term_id = isset($cvalue['value']) ? $cvalue['value'] : ''; $term_id = absint($term_id); if ($term_id > 0) { $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : ''; if (!empty($taxonomy)) { $tax_item = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_id); $query_args = hocwp_query_sanitize_tax_query($tax_item, $query_args); $get_by = true; } } } break; case 'related': $get_by = true; break; case 'like': $get_by = true; $query_args['meta_key'] = 'likes'; $query_args['orderby'] = 'meta_value_num'; break; case 'view': $get_by = true; $query_args['meta_key'] = 'views'; $query_args['orderby'] = 'meta_value_num'; break; case 'featured': $get_by = true; hocwp_query_sanitize_featured_args($query_args); break; case 'favorite': break; case 'rate': break; } $get_by = apply_filters('hocwp_widget_post_get_by_check_status', $get_by, $args, $instance, $this); if ($get_by) { $query_args = apply_filters('hocwp_widget_post_query_args', $query_args, $args, $instance, $this); if ('related' == $by) { $w_query = hocwp_query_related_post($query_args); } else { $w_query = hocwp_query($query_args); } } $widget_html = hocwp_get_value_by_key($args, 'before_widget') . $title; $widget_html .= '<div class="' . $content_class . '">'; $widget_post_pre_html = apply_filters('hocwp_widget_post_pre_html', '', $args, $instance, $this); if (!empty($widget_post_pre_html)) { $widget_html .= $widget_post_pre_html; } else { if ($w_query->have_posts()) { $widget_html .= apply_filters('hocwp_widget_post_before_loop', '', $args, $instance, $this); if ((bool) $slider) { $four_posts = array_slice($w_query->posts, 0, 4); $next_posts = array_slice($w_query->posts, 4, absint($w_query->post_count - 4)); $widget_content = apply_filters('hocwp_widget_post_pre_slider_html', '', $args, $instance, $this); if (empty($widget_content)) { $carousel_id = $this->id; $carousel_id = hocwp_sanitize_id($carousel_id); $count = 0; ob_start(); ?> <div id="<?php echo $carousel_id; ?> " class="carousel slide" data-ride="carousel"> <div class="carousel-inner" role="listbox"> <?php foreach ($four_posts as $post) { setup_postdata($post); $class = 'item'; if (0 == $count) { hocwp_add_string_with_space_before($class, 'active'); } ?> <div class="<?php echo $class; ?> "> <?php hocwp_article_before(); do_action('hocwp_widget_post_slider_before_post', $args, $instance, $this); if (!(bool) $hide_thumbnail) { if ('coupon' == $post->post_type) { $store = hocwp_get_coupon_store($post->ID); echo '<div class="text-center store-logo">'; hocwp_term_the_thumbnail(array('term' => $store, 'width' => 180, 'height' => 110)); echo '</div>'; } else { hocwp_post_thumbnail(array('width' => 300, 'height' => 200)); } } do_action('hocwp_widget_post_slider_before_post_title', $args, $instance, $this); hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length))); do_action('hocwp_widget_post_slider_after_post_title', $args, $instance, $this); hocwp_entry_summary($excerpt_length); do_action('hocwp_widget_post_slider_after_post', $args, $instance, $this); hocwp_article_after(); ?> </div> <?php $count++; } wp_reset_postdata(); ?> </div> <ol class="carousel-indicators list-inline list-unstyled"> <?php $count = count($four_posts); for ($i = 0; $i < $count; $i++) { $indicator_class = 'indicator-item'; if (0 == $i) { hocwp_add_string_with_space_before($indicator_class, 'active'); } ?> <li data-target="#<?php echo $carousel_id; ?> " data-slide-to="<?php echo $i; ?> " class="<?php echo $indicator_class; ?> "> <span><?php echo $i + 1; ?> </span> </li> <?php } ?> </ol> <a class="left carousel-control" href="#<?php echo $carousel_id; ?> " role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only"><?php _e('Previous', 'hocwp-theme'); ?> </span> </a> <a class="right carousel-control" href="#<?php echo $carousel_id; ?> " role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only"><?php _e('Next', 'hocwp-theme'); ?> </span> </a> </div> <?php $widget_content = ob_get_clean(); if (hocwp_array_has_value($next_posts)) { $w_query->posts = $next_posts; $w_query->post_count = count($next_posts); ?> <div class="more-posts"> <?php $widget_content .= $this->list_post_html($args, $instance, $w_query); ?> </div> <?php } } $widget_content = apply_filters('hocwp_widget_post_slider_html', $widget_content, $args, $instance, $this); $widget_html .= $widget_content; } else { $widget_html .= $this->list_post_html($args, $instance, $w_query); } $widget_html .= apply_filters('hocwp_widget_post_after_loop', '', $args, $instance, $this); } else { $widget_html .= '<p class="nothing-found">' . __('Nothing found!', 'hocwp-theme') . '</p>'; } } $widget_html = apply_filters('hocwp_widget_post_html', $widget_html, $args, $instance, $this); $widget_html .= '</div>'; $widget_html .= hocwp_get_value_by_key($args, 'after_widget'); echo $widget_html; }