function widget($args, $instance) { $cache = nxt_cache_get('widget_recent_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; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 10; } $r = new nxt_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true)); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul> <?php while ($r->have_posts()) { $r->the_post(); ?> <li><a href="<?php the_permalink(); ?> " title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?> "><?php if (get_the_title()) { the_title(); } else { the_ID(); } ?> </a></li> <?php } ?> </ul> <?php echo $after_widget; // Reset the global $the_post as this query will have stomped on it nxt_reset_postdata(); } $cache[$args['widget_id']] = ob_get_flush(); nxt_cache_set('widget_recent_posts', $cache, 'widget'); }
function woo_get_posts_by_taxonomy($args = null) { global $nxt_query; $posts = array(); /* Parse arguments, and declare individual variables for each. */ $defaults = array('limit' => 5, 'post_type' => 'any', 'taxonomies' => 'post_tag, category', 'specific_terms' => '', 'relationship' => 'OR', 'order' => 'DESC', 'orderby' => 'date', 'operator' => 'IN', 'exclude' => ''); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); // Make sure the order value is safe. if (!in_array($order, array('ASC', 'DESC'))) { $order = $defaults['order']; } // Make sure the orderby value is safe. if (!in_array($orderby, array('none', 'id', 'author', 'title', 'date', 'modified', 'parent', 'rand', 'comment_count', 'menu_order'))) { $orderby = $defaults['orderby']; } // Make sure the operator value is safe. if (!in_array($operator, array('IN', 'NOT IN', 'AND'))) { $orderby = $defaults['operator']; } // Convert our post types to an array. if (!is_array($post_type)) { $post_type = explode(',', $post_type); } // Convert our taxonomies to an array. if (!is_array($taxonomies)) { $taxonomies = explode(',', $taxonomies); } // Convert exclude to an array. if (!is_array($exclude) && $exclude != '') { $exclude = explode(',', $exclude); } if (!count((array) $taxonomies)) { return; } // Clean up our taxonomies for use in the query. if (count($taxonomies)) { foreach ($taxonomies as $k => $v) { $taxonomies[$k] = trim($v); } } // Determine which terms we're going to relate to this entry. $related_terms = array(); foreach ($taxonomies as $t) { $terms = get_terms($t, 'orderby=id&hide_empty=1'); if (!empty($terms)) { foreach ($terms as $k => $v) { $related_terms[$t][$v->term_id] = $v->slug; } } } // If specific terms are available, use those. if (!is_array($specific_terms)) { $specific_terms = explode(',', $specific_terms); } if (count($specific_terms)) { foreach ($specific_terms as $k => $v) { $specific_terms[$k] = trim($v); } } // Look for posts with the same terms. // Setup query arguments. $query_args = array(); if ($post_type) { $query_args['post_type'] = $post_type; } if ($limit) { $query_args['posts_per_page'] = $limit; // $query_args['nopaging'] = true; } // Setup specific posts to exclude. if (count($exclude) > 0) { $query_args['post__not_in'] = $exclude; } $query_args['order'] = $order; $query_args['orderby'] = $orderby; $query_args['tax_query'] = array(); // Setup for multiple taxonomies. if (count($related_terms) > 1) { $query_args['tax_query']['relation'] = $args['relationship']; } // Add the taxonomies to the query arguments. foreach ((array) $related_terms as $k => $v) { $terms_for_search = array_values($v); if (count($specific_terms)) { $specific_terms_by_tax = array(); foreach ($specific_terms as $i => $j) { if (in_array($j, array_values($v))) { $specific_terms_by_tax[] = $j; } } if (count($specific_terms_by_tax)) { $terms_for_search = $specific_terms_by_tax; } } $query_args['tax_query'][] = array('taxonomy' => $k, 'field' => 'slug', 'terms' => $terms_for_search, 'operator' => $operator); } if (empty($query_args['tax_query'])) { return; } $query_saved = $nxt_query; $query = new nxt_Query($query_args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $posts[] = $query->post; } } $query = $query_saved; nxt_reset_query(); return $posts; }
function widget($args, $instance) { $cache = nxt_cache_get('widget_recent_posts', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts', 'huddle') : $instance['title'], $instance, $this->id_base); if (!($number = absint($instance['number']))) { $number = 10; } $thumbs = isset($instance['thumbs']) && $instance['thumbs']; $show = isset($instance['show']) ? $instance['show'] : 'recent'; $nxtq_args = array('posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true); if ($show == 'popular') { $nxtq_args['orderby'] = 'comment_count'; } $r = new nxt_Query($nxtq_args); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <?php while ($r->have_posts()) { $r->the_post(); ?> <div class="post"> <div class="post-img fl"><a href="<?php the_permalink(); ?> "><?php the_post_thumbnail('post-small'); ?> </a></div> <h4 class="post-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h4> <span> <?php _e('On', 'huddle'); ?> <?php the_time(get_option('date_format')); ?> , <?php _e('with', 'huddle'); ?> <?php comments_popup_link(__('0 Comments', 'huddle'), __('1 Comment', 'huddle'), __('% Comments', 'huddle')); ?> </span> <div class="clf"></div> </div><!--post--> <?php } ?> <?php echo $after_widget; ?> <?php // Reset the global $the_post as this query will have stomped on it nxt_reset_postdata(); } $cache[$args['widget_id']] = ob_get_flush(); nxt_cache_set('widget_recent_posts', $cache, 'widget'); }
* * The loop that displays posts * * @author Bowe Frankema <*****@*****.**> * @link http://infinity.presscrew.com/ * @copyright Copyright (C) 2010-2011 Bowe Frankema * @license http://www.gnu.org/licenses/gpl.html GPLv2 or later * @package Infinity * @subpackage templates * @since 1.0 */ $temp = $nxt_query; $nxt_query = null; $nxt_query = new nxt_Query(); $nxt_query->query('posts_per_page=5' . '&paged=' . $paged); while ($nxt_query->have_posts()) { $nxt_query->the_post(); ?> <!-- post --> <article class="post" id="post-<?php the_ID(); ?> " <?php post_class(); ?> > <?php do_action('open_loop_post'); ?> <!-- post-content --> <div class="post-content">
the_category(', '); } if (in_array('comments', get_option('modest_postinfo1'))) { ?> | <?php comments_popup_link(esc_html__('0 comments', 'Modest'), esc_html__('1 comment', 'Modest'), '% ' . esc_html__('comments', 'Modest')); } ?> </p> <?php } elseif (is_single() && get_option('modest_postinfo2') != '') { ?> <?php global $query_string; $new_query = new nxt_Query($query_string); while ($new_query->have_posts()) { $new_query->the_post(); } ?> <?php esc_html_e('Posted', 'Modest'); ?> <?php if (in_array('author', get_option('modest_postinfo2'))) { ?> <?php esc_html_e('by', 'Modest'); ?> <?php the_author_posts_link(); }
function widget($args, $instance) { global $nxtdb; extract($args); $title = apply_filters('widget_title', $instance['title']); $title_popular = $instance['title_popular']; $title_recent = $instance['title_recent']; $title_comments = $instance['title_comments']; $display_count = $instance['display_count']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="tabs"> <li><a class="btn-small"><span><?php echo $title_popular; ?> </span></a></li> <li><a><span><?php echo $title_recent; ?> </span></a></li> <li><a><span><?php echo $title_comments; ?> </span></a></li> </ul> <div class="clear"></div> <div class="panes"> <?php // Popular Posts $huddle_popular_posts = new nxt_Query(); $huddle_popular_posts->query('shonxtosts=' . $display_count . '&orderby=comment_count'); ?> <div class="pane"> <?php // Start the loop while ($huddle_popular_posts->have_posts()) { $huddle_popular_posts->the_post(); ?> <div class="post"> <div class="post-img fl"><a href="<?php the_permalink(); ?> "><?php the_post_thumbnail('post-small'); ?> </a></div> <h4 class="post-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h4> <span> <?php _e('On', 'huddle'); ?> <?php the_time(get_option('date_format')); ?> , <?php _e('with', 'huddle'); ?> <?php comments_popup_link(__('0 Comments', 'huddle'), __('1 Comment', 'huddle'), __('% Comments', 'huddle')); ?> </span> <div class="clf"></div> </div><!--post--> <?php // End the loop } nxt_reset_query(); ?> </div><!--pane--> <?php // Recent Posts $huddle_recent_posts = new nxt_Query(); $huddle_recent_posts->query('shonxtosts=' . $display_count . ''); ?> <div class="pane"> <?php // Start the loop while ($huddle_recent_posts->have_posts()) { $huddle_recent_posts->the_post(); ?> <div class="post"> <div class="post-img fl"><a href="<?php the_permalink(); ?> "><?php the_post_thumbnail('post-small'); ?> </a></div> <h4 class="post-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h4> <span> <?php _e('On', 'huddle'); ?> <?php the_time(get_option('date_format')); ?> , <?php _e('with', 'huddle'); ?> <?php comments_popup_link(__('0 Comments', 'huddle'), __('1 Comment', 'huddle'), __('% Comments', 'huddle')); ?> </span> <div class="clf"></div> </div><!--post--> <?php // End the loop } nxt_reset_query(); ?> </div><!--pane--> <?php // Recent Comments ?> <div class="pane"> <?php // Query for comments global $nxtdb; $huddle_recent_comments_query = "SELECT DISTINCT ID, post_title, post_password, comment_ID,\n\t\t\t\tcomment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved,\n\t\t\t\tcomment_type,comment_author_url,\n\t\t\t\tSUBSTRING(comment_content,1,50) AS comment_excerpt\n\t\t\t\tFROM {$nxtdb->comments}\n\t\t\t\tLEFT OUTER JOIN {$nxtdb->posts} ON ({$nxtdb->comments}.comment_post_ID =\n\t\t\t\t{$nxtdb->posts}.ID)\n\t\t\t\tWHERE comment_approved = '1' AND comment_type = '' AND\n\t\t\t\tpost_password = ''\n\t\t\t\tORDER BY comment_date_gmt DESC LIMIT " . $display_count; $huddle_recent_comments = $nxtdb->get_results($huddle_recent_comments_query); foreach ($huddle_recent_comments as $huddle_recent_comment) { ?> <div class="post clf"> <div class="post-img"><?php echo get_avatar($huddle_recent_comment, 35); ?> </div> <div class="post-txt"> <h4 class="post-title"><a href="<?php echo get_permalink($huddle_recent_comment->ID); ?> #comment-<?php echo $huddle_recent_comment->comment_ID; ?> "><?php echo strip_tags($huddle_recent_comment->comment_author); ?> </a></h4> <span class="em"><?php echo strip_tags($huddle_recent_comment->comment_excerpt); ?> ...</span> </div> </div><!--post--> <?php } ?> </div><!--pane--> </div><!--panes--> <?php echo $after_widget; }