SHOW:
|
|
- or go back to the newest paste.
| 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 | return $instance; | |
| 23 | } | |
| 24 | ||
| 25 | ||
| 26 | - | public function alterNumberOfEvents($query) {
|
| 26 | + | function alterNumberOfEvents($query) {
|
| 27 | $query->query_vars['posts_per_page'] = $this->numEvents; | |
| 28 | remove_filter('parse_query', array($this, 'alterNumberOfEvents'));
| |
| 29 | return $query; | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | ||
| 34 | // Modify the Next Event widget to show 5 events | |
| 35 | new NextEventWidgetModification(5); |