function gazeta_post_meta($content) { global $post; if (!isset($post->ID) || get_post_type($post) != 'post' && !is_single() && is_main_query()) { return $content; } ob_start(); ?> <div class="ns-meta entry-meta"> <div class="nsm-inner"> <span><i class="fa fa-clock-o"></i> <a href="<?php print gazeta_get_post_archive_link($post->ID); ?> "><?php print get_the_date(); ?> </a></span> <?php if (get_comments_number()) { ?> <span><a href="<?php comments_link(); ?> "><i class="fa fa-comments"></i> <?php print get_comments_number(); ?> </a></span> <?php if (gazeta_get_post_views($post->ID) > 0) { ?> <span><i class="fa fa-eye"></i> <?php print gazeta_get_post_views($post->ID); ?> </span> <?php } ?> <?php } ?> <?php do_action('gazeta_post_meta/meta'); ?> </div> </div> <?php return $content . ob_get_clean(); }
function widget($args, $instance) { $output = ''; wp_reset_postdata(); $current_post_tags = $current_post_categories = null; $current_post = get_the_ID(); $title = !empty($instance['title']) ? apply_filters('widget_title', esc_attr($instance['title'])) : null; $id = isset($instance['id']) ? esc_attr($instance['id']) : ''; $expiration = isset($instance['expiration']) ? esc_attr($instance['expiration']) : ''; $layout = isset($instance['layout']) ? esc_attr($instance['layout']) : 'classic'; $shows_thumbnail_image = isset($instance['shows_thumbnail_image']) ? esc_attr($instance['shows_thumbnail_image']) : ''; $thumbnail_size = isset($instance['thumbnail_size']) ? esc_attr($instance['thumbnail_size']) : ''; $post_format = isset($instance['post_format']) ? esc_attr($instance['post_format']) : ''; $author__in = isset($instance['author__in']) ? esc_attr($instance['author__in']) : ''; $post_tags = isset($instance['post_tags']) ? esc_attr($instance['post_tags']) : ''; $post_categories = isset($instance['post_categories']) ? esc_attr($instance['post_categories']) : ''; $sticky = isset($instance['ignore_sticky_posts']) ? esc_attr($instance['ignore_sticky_posts']) : 'on'; $orderby = isset($instance['orderby']) ? esc_attr($instance['orderby']) : 'ID'; $order = isset($instance['order']) ? esc_attr($instance['order']) : 'DESC'; $posts_per_page = isset($instance['posts_per_page']) ? absint($instance['posts_per_page']) : 5; $widget_id = isset($this->id) ? $this->id : $id; if (!isset($expiration)) { $expiration = apply_filters('transient_expiration', 300); } $post_data = array('no_found_rows' => true, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'orderby' => $orderby == 'view' ? 'meta_value_num' : $orderby, 'order' => $order, 'post__not_in' => array($current_post)); // order by views if ($orderby == 'view') { $post_data['meta_key'] = GAZETA_POST_VIEWS_FIELD_NAME; } if (!empty($author__in)) { $author__in = explode(",", $author__in); if (is_array($author__in) && !empty($author__in)) { $post_data['author__in'] = $author__in; } } // Post formats if (!empty($post_format)) { $post_format = explode(",", $post_format); if (is_array($post_format) && !empty($post_format)) { $post_data['tax_query'][] = array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $post_format, 'operator' => 'IN'); } } // Post Tags if (!empty($post_tags)) { $post_tags = explode(",", $post_tags); if (is_array($post_tags) && !empty($post_tags)) { $post_data['tag_slug__in'] = $post_tags; } } // Post Categories if (!empty($post_categories)) { $post_categories = explode(",", $post_categories); if (is_array($post_categories) && !empty($post_categories)) { $post_data['category__in'] = $post_categories; } } // $sticky if ($sticky == 'on') { $post_data['ignore_sticky_posts'] = true; } $post_data = apply_filters('gazeta_posts_widget/args', $post_data, $this->id); $post_query = new WP_Query($post_data); if ($layout == 'modern') { $before_widget = str_ireplace("p-news", "m-comment", $args['before_widget']); echo $before_widget; } else { echo $args['before_widget']; } if ($title) { echo $args['before_title'] . $title . $args['after_title']; } $hide_thumbnail_image = empty($shows_thumbnail_image) ? 'no-post-thumbnail' : null; if (false !== ($output = get_transient($widget_id)) && apply_filters('is_cache_active', true) === true) { // check if the cache is exists. echo $output; } else { if ($post_query->have_posts()) { // classic layout if ($layout == 'classic') { $output .= '<div class="sw-inner"><ul>'; while ($post_query->have_posts()) { $post_query->the_post(); $output .= ' <li class="' . join(' ', get_post_class('post-item', '')) . '">'; if (has_post_thumbnail(get_the_ID()) && !empty($shows_thumbnail_image)) { $output .= '<div class="post-thumnail-image">'; $output .= '<a href="' . get_permalink(get_the_ID()) . '">'; $output .= get_the_post_thumbnail(get_the_ID(), apply_filters('gazeta_aside_posts_widget/thumbnail_size', $thumbnail_size), array('class' => 'img-responsive')); $output .= '</a>'; $output .= '</div>'; } $output .= ' <div class="pn-info ' . $hide_thumbnail_image . '">'; if (has_category('', get_the_ID())) { $output .= '<span class="cat-default">'; $output .= get_the_category_list(', '); $output .= '</span>'; } $output .= ' <em> <a href="' . gazeta_get_post_archive_link(get_the_ID()) . '"><i class="fa fa-clock-o"></i> ' . apply_filters('gazeta_aside_posts_widget/time_format', get_the_date()) . '</a>'; if (get_comments_number(get_the_ID())) { $output .= '<a href="' . get_comments_link(get_the_ID()) . '"><i class="fa fa-comments"></i> ' . get_comments_number(get_the_ID()) . '</a>'; } $output .= ' </em> <h4 class="post-title"><a href="' . get_permalink(get_the_ID()) . '">' . get_the_title() . '</a></h4> </div> </li> '; } $output .= '</ul></div>'; // end inner. } else { // modern layout $output .= '<ul>'; while ($post_query->have_posts()) { $post_query->the_post(); $output .= ' <li>'; if (has_post_thumbnail(get_the_ID())) { $output .= get_the_post_thumbnail(get_the_ID(), apply_filters('gazeta_aside_posts_widget/thumbnail_size', $thumbnail_size), array('class' => 'img-responsive')); } if (get_post_format(get_the_ID()) == 'video') { $output .= '<i class="fa fa-play"></i>'; } if (has_category('', get_the_ID())) { $output .= '<span>'; $output .= get_the_category_list(', '); $output .= '</span>'; } $output .= ' <h4><a href="' . get_permalink(get_the_ID()) . '">' . get_the_title() . '</a></h4> </li> '; } $output .= '</ul>'; } } else { $output .= '<div class="alert alert-warning" role="alert">' . __('Nothing found!', 'gazeta') . '</div>'; } if (apply_filters('is_cache_active', true) === true) { set_transient($widget_id, $output, $expiration); } echo $output; } echo $args['after_widget']; wp_reset_postdata(); }
/** * * @param unknown_type $attr * @param unknown_type $content */ function gazeta_category_block_shortcode($attr, $content = null) { $output = $category_link = $sc_output = ''; $post_array = array(); $current_post = get_the_ID(); wp_reset_postdata(); extract(shortcode_atts(array('heading' => '', 'id' => 'category_block-' . rand(1000, 9999), 'post_format' => '', 'author__in' => '', 'post_tags' => '', 'post_category' => '', 'ignore_sticky_posts' => 'yes', 'orderby' => 'ID', 'order' => 'DESC', 'posts_per_page' => get_option('posts_per_page'), 'thumbnail_size' => 'image-280-435', 'hide_post_no_featured_image' => 'yes', 'el_class' => 'category_block-' . rand(1000, 9999), 'show_excerpt' => 'yes', 'excerpt_length' => 30, 'expiration' => 300), $attr)); $post_data = array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'orderby' => $orderby == 'view' ? 'meta_value_num' : $orderby, 'order' => $order, 'post__not_in' => isset($current_post) ? array($current_post) : '', 'cat' => isset($post_category) ? (int) $post_category : '', 'no_found_rows' => true); if (!empty($author__in)) { $author__in = explode(",", $author__in); if (is_array($author__in) && !empty($author__in)) { $post_data['author__in'] = $author__in; } } if (isset($post_category)) { $category_link = get_category_link($post_category); } // order by views if ($orderby == 'view') { $post_data['meta_key'] = defined('GAZETA_POST_VIEWS_FIELD_NAME') ? GAZETA_POST_VIEWS_FIELD_NAME : 'post_views'; } // Post formats if (!empty($post_format)) { $post_format = explode(",", $post_format); if (is_array($post_format) && !empty($post_format)) { $post_data['tax_query'][] = array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $post_format, 'operator' => 'IN'); } } // Post Tags if (!empty($post_tags)) { $post_tags = explode(",", $post_tags); if (is_array($post_tags) && !empty($post_tags)) { $post_data['tag_slug__in'] = $post_tags; } } // $sticky if ($ignore_sticky_posts == 'yes' || $ignore_sticky_posts === true) { $post_data['ignore_sticky_posts'] = true; } if ($hide_post_no_featured_image == 'yes') { $post_data['meta_query'] = array(array('key' => '_thumbnail_id', 'compare' => '!=', 'value' => '')); } if (false !== ($output = get_transient($id)) && apply_filters('is_cache_active', true) === true) { return $output; } else { $post_data = apply_filters('gazeta_category_block/args', $post_data, $id); $post_query = new WP_Query($post_data); $first_post_id = 0; if ($post_query->have_posts()) { add_filter('excerpt_more', function () { return '...'; }); $output .= '<div class="cat-blocks ' . $el_class . '" id="' . $id . '">'; if (!empty($heading)) { if (!empty($category_link)) { $output .= '<h4 class="section-heading"><span><a href="' . esc_url($category_link) . '">' . esc_attr($heading) . '</a></span></h4>'; } else { $output .= '<h4 class="section-heading"><span>' . esc_attr($heading) . '</span></h4>'; } } while ($post_query->have_posts()) { $post_query->the_post(); $post_array[] = get_the_ID(); } $output .= '<div class="row">'; if (isset($post_array[0]) && has_post_thumbnail($post_array[0])) { $first_post_id = $post_array[0]; $output .= ' <div class="col-md-6"> <div class="cb-big">'; $output .= get_the_post_thumbnail($post_array[0], apply_filters('gazeta_category_block/thumbnail_size', $thumbnail_size, $id), array('class' => 'img-responsive')); $output .= ' </div> </div> '; unset($post_array[0]); $post_array = array_unique($post_array); } if (is_array($post_array) && !empty($post_array)) { $output .= ' <div class="col-md-6 cb-info"> <h5 class="post-title"><a href="' . get_permalink($first_post_id) . '">' . get_the_title($first_post_id) . '</a></h5> <span class="date"> <a href="' . gazeta_get_post_archive_link($first_post_id) . '"><i class="fa fa-clock-o"></i> ' . get_the_date(apply_filters('gazeta_category_block/time_format', ''), $first_post_id) . '</a>'; if (get_comments_number($first_post_id)) { $output .= '<a href="' . get_comments_link($first_post_id) . '"><i class="fa fa-comments"></i> ' . get_comments_number($first_post_id) . '</a>'; } $output .= ' </span>'; if ($show_excerpt == 'yes') { add_filter('excerpt_length', function () use($excerpt_length) { return $excerpt_length; }); $output .= '<p class="entry-content">' . get_the_excerpt() . '</p>'; } $output .= ' <ul>'; for ($i = 1; $i <= count($post_array); $i++) { $output .= '<li class="post-title"><a href="' . get_permalink($post_array[$i]) . '">' . get_the_title($post_array[$i]) . '</a></li>'; } $output .= ' </ul> </div> '; } $output .= '</div><!-- end row -->'; $output .= '<div class="space40"></div> </div>'; } if (apply_filters('is_cache_active', true) === true) { set_transient($id, $output, apply_filters('transient_expiration', $expiration)); } } wp_reset_postdata(); return $output; }