function widget($args, $instance) { extract($args); if (!is_single()) { return; } $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } echo dp_get_post_stats(); echo $after_widget; }
function widget($args, $instance) { $cache = wp_cache_get('dp_widget_posts', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } $style = isset($instance['style']) ? $instance['style'] : 'list'; extract($args); ob_start(); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'dp') : $instance['title'], $instance, $this->id_base); $query_args = $instance; $query_args['no_found_rows'] = true; $query_args = dp_parse_query_args($query_args); $r = new WP_Query(apply_filters('dp_widget_posts_args', $query_args)); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="<?php echo 'post-' . $style; ?> "> <?php while ($r->have_posts()) { $r->the_post(); $item_format = is_video() ? 'video' : 'post'; ?> <li class="item cf <?php echo 'item-' . $item_format; ?> "> <?php $image_size = $style == 'list-full' ? 'custom-medium' : 'custom-small'; dp_thumb_html($image_size); ?> <div class="data"> <h4 class="entry-title"><a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title()); ?> "><?php the_title(); ?> </a></h4> <p class="meta"> <span class="author"><?php _e('Added by', 'dp'); ?> <?php the_author_posts_link(); ?> </span> <span class="time"><?php printf(__('%s ago', 'dp'), human_time(get_the_time('U'))); ?> </span> </p> <p class="stats"><?php echo dp_get_post_stats(); ?> </p> </div> </li> <?php } ?> </ul> <?php echo $after_widget; ?> <?php // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('dp_widget_posts', $cache, 'widget'); }
function widget($args, $instance) { if (!is_singular()) { return; } $cache = wp_cache_get('dp_widget_related_posts', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } $style = isset($instance['style']) ? $instance['style'] : 'list'; extract($args); ob_start(); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'dp') : $instance['title'], $instance, $this->id_base); ?> <?php echo $before_widget; ?> <?php $r = dp_related_posts(array('number' => $instance['posts_per_page'], 'fields' => 'object')); if (!$r || !is_object($r) || !$r->have_posts()) { return; } ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="<?php echo 'post-' . $style; ?> "> <?php while ($r->have_posts()) { $r->the_post(); $item_format = is_video() ? 'video' : 'post'; ?> <li class="item cf <?php echo 'item-' . $item_format; ?> "> <?php $image_size = $style == 'list-full' ? 'custom-medium' : 'custom-small'; dp_thumb_html($image_size); ?> <div class="data"> <h4 class="entry-title"><a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title()); ?> "><?php the_title(); ?> </a></h4> <p class="meta"> <span class="author"><?php _e('Added by', 'dp'); ?> <?php the_author_posts_link(); ?> </span> <span class="time"><?php printf(__('%s ago', 'dp'), human_time(get_the_time('U'))); ?> </span> </p> <p class="stats"><?php echo dp_get_post_stats(); ?> </p> </div> </li> <?php } wp_reset_query(); ?> </ul> <?php echo $after_widget; ?> <?php $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('dp_widget_related_posts', $cache, 'widget'); }
<p class="entry-meta"> <span class="author vcard"> <?php printf('<a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by %s', 'dp'), get_the_author())), get_the_author()); ?> </span> <time class="entry-date" datetime="<?php echo esc_attr(get_the_date('c')); ?> "><?php printf(__('%s ago', 'dp'), human_time(get_the_time('U'))); ?> </time></a> </p> <p class="stats"><?php echo dp_get_post_stats(); ?> </p> <p class="entry-summary"><?php dp_excerpt(); ?> </p> </div> </div><!-- end #post-<?php the_ID(); ?> -->