Advertisement
BakerMan

Show Multiple Events via the Next Events Widget

Oct 16th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. /**
  2.  * This class can change the Next Event widget query so that the number of
  3.  * returned posts (events) is something other than 1.
  4.  *
  5.  * You could add this to your theme's functions.php file or bundle it up inside
  6.  * a plugin (for TEC/ECP 2.0.9).
  7.  */
  8. class NextEventWidgetModification {
  9.     protected $numEvents = 1;
  10.  
  11.  
  12.     public function __construct($numEvents) {
  13.         $this->numEvents = absint($numEvents);
  14.         add_filter('widget_display_callback', array($this, 'listenForWidget'), 10, 2);
  15.     }
  16.  
  17.  
  18.     public function listenForWidget($instance, $object) {
  19.         if ($object->name === 'Next Event Widget')
  20.             add_filter('parse_query', array($this, 'alterNumberOfEvents'));
  21.     }
  22.  
  23.  
  24.     public function alterNumberOfEvents($query) {
  25.         $query->query_vars['posts_per_page'] = $this->numEvents;
  26.         return $query;
  27.     }
  28. }
  29.  
  30.  
  31. // Modify the Next Event widget to show 5 events
  32. new NextEventWidgetModification(5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement