Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This class can change the Next Event widget query so that the number of
- * returned posts (events) is something other than 1.
- *
- * You could add this to your theme's functions.php file or bundle it up inside
- * a plugin (for TEC/ECP 2.0.9).
- */
- class NextEventWidgetModification {
- protected $numEvents = 1;
- public function __construct($numEvents) {
- $this->numEvents = absint($numEvents);
- add_filter('widget_display_callback', array($this, 'listenForWidget'), 10, 2);
- }
- public function listenForWidget($instance, $object) {
- if ($object->name === 'Next Event Widget')
- add_filter('parse_query', array($this, 'alterNumberOfEvents'));
- }
- public function alterNumberOfEvents($query) {
- $query->query_vars['posts_per_page'] = $this->numEvents;
- return $query;
- }
- }
- // Modify the Next Event widget to show 5 events
- new NextEventWidgetModification(5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement