/**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     $title = isset($instance['title']) ? $instance['title'] : $taxonomy->label;
     $num = isset($instance['num']) ? trim($instance['num']) : 10;
     $taxonomy = isset($instance['taxonomy']) && is_array($instance['taxonomy']) ? $instance['taxonomy'] : array('post_tag');
     $term_from = isset($instance['term_from']) ? trim($instance['term_from']) : '-3 days';
     $term_to = isset($instance['term_to']) ? trim($instance['term_to']) : 'today';
     $term_args = array('count' => $num, 'from' => $term_from, 'to' => $term_to);
     // support injecting the taxonomy name into the title
     if (FALSE !== strpos($title, '_TAXONOMY_')) {
         $queried = get_queried_object();
         $title = str_replace('_TAXONOMY_', $queried->name, $title);
         $term_args['tax_query'][] = array('taxonomy' => $queried->taxonomy, 'field' => 'term_id', 'terms' => array($queried->term_id));
     }
     //end if
     $terms = go_popular()->get_popular_terms($taxonomy, $term_args);
     echo $args['before_widget'];
     include __DIR__ . '/templates/widget-terms.php';
     echo $args['after_widget'];
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     global $wp_taxonomies;
     if (!isset($wp_taxonomies[$instance['taxonomy']])) {
         return;
     }
     //end if
     $taxonomy = $wp_taxonomies[$instance['taxonomy']];
     $title = isset($instance['title']) ? $instance['title'] : $taxonomy->label;
     $num = isset($instance['num']) ? trim($instance['num']) : 3;
     $num_news = isset($instance['num_news']) ? trim($instance['num_news']) : 3;
     $num_research = isset($instance['num_research']) ? trim($instance['num_research']) : 1;
     $term_from = isset($instance['term_from']) ? trim($instance['term_from']) : '-3 days';
     $term_to = isset($instance['term_to']) ? trim($instance['term_to']) : 'today';
     $article_from = isset($instance['article_from']) ? trim($instance['article_from']) : '-7 days';
     $article_to = isset($instance['article_to']) ? trim($instance['article_to']) : 'today';
     $term_args = array('count' => $num, 'from' => $term_from, 'to' => $term_to);
     $terms = go_popular()->get_popular_terms($taxonomy->name, $term_args);
     foreach ($terms as $index => $term) {
         $args = array('count' => $num_news, 'from' => $article_from, 'to' => $article_to);
         $terms[$index]->popular_posts = array();
         $terms[$index]->popular_posts['news'] = go_popular()->get_popular_posts_by_term('news', $taxonomy->name, $term->slug, $args);
         $args['count'] = $num_research;
         $terms[$index]->popular_posts['research'] = go_popular()->get_popular_posts_by_term('research', $taxonomy->name, $term->slug, $args);
     }
     // end foreach
     echo $args['before_widget'];
     include __DIR__ . '/templates/widget.php';
     echo $args['after_widget'];
 }
Exemple #3
0
<?php

/**
 * Plugin Name: Gigaom Popular Stuff
 * Version: 0.1
 * Plugin URI: http://gigaom.com
 * Description: Determines popular terms/posts by taxonomy
 * Author: Gigaom Network
 * Author URI: http://gigaom.com
 * Contributors: borkweb, zbtirrell
 * Tags: standards
 * License: MIT
 * License URI: http://opensource.org/licenses/mit-license.php
 */
require_once __DIR__ . '/components/class-go-popular.php';
go_popular();