Goto Admincp->vBullietin CMS->Widgets->Create New Widget
Choose PHP Direct Execution as Widget's Type
Place a Title. eg Upcoming Events. Keep it short as this is what will appear as title on your pages.
Click Save
Click Configure on the right of the new created widget.
Remove the default code that appears. Be sure to not leave behind even a single letter.
Copy and Paste the code that you can find below.
Leave the template name as is (vbcms_widget_execphp_page)
Click Save
Goto Admincp->vBullietin CMS->Layout Manager
Click Go on the Default Layout
Add the Widget to your Layout
Click Save
That's all !!
PHP Code
PHP Code:
ob_start();
// %d
$show_count = 5;
$query = sprintf("SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from > '%d' || ( dateline_from > '%d' AND dateline_to < '%d' )) ORDER BY dateline_from ASC LIMIT %d",TIMENOW,TIMENOW,TIMENOW,$show_count);
I have updated the code to work with single-day events, events that have already started but havn't ended, etc. Thanks to tomsch for the mkdate snippet!
I believe I got user time zone correction to work. Please see the following code:
Note: This version checks for the user's preferred date and time display settings (i.e. UK vs US, etc) and displays things accordingly. This can also pull from one or more selected calendars, per the instructions below (see orange comments).
PHP Code:
ob_start(); //Change $show_count to change how many events to display in the block $show_count = 5; //Get the user's time zone $user_tz = vB::$vbulletin->userinfo['timezoneoffset']; $tz_adjust = $user_tz * 3600; $mydate = mktime(0, 0, 0, date("m"), date("d")-1, date("Y"));
//Get events from the table //Use the code below to pull from ALL calendars $query = sprintf(" SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from >= '$mydate' || (dateline_from >= '$mydate' AND dateline_to <= '$mydate' ) || ('$mydate' BETWEEN dateline_from AND dateline_to)) ORDER BY dateline_from ASC LIMIT $show_count"); //To pull from just certain calendars, comment out the above $query and uncomment the line below. Change the "AND calendarids in (1, 2, 3)" to match your calendar IDs to pull //$query = sprintf(" SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from >= '$mydate' || (dateline_from >= '$mydate' AND dateline_to <= '$mydate' ) || ('$mydate' BETWEEN dateline_from AND dateline_to)) AND calendarids in (1, 2, 3) ORDER BY dateline_from ASC LIMIT $show_count"); $event_get = vB::$db->query_read($query); $output_bits = ''; while($event = vB::$db->fetch_array($event_get)) {
// Convert user timezone offset into minutes $offset = $user_tz; // Only adjust start times for ranged events; all-day events should keep their midnight start time. if($event['dateline_to'] == 0 ) { $from = $event['dateline_from']; } else { $from = $event['dateline_from'] + $tz_adjust; } $to = $event['dateline_to'] + $tz_adjust;
i want to display the next event for the next 7 days like you can at the bottom of the main forum display
however i want them to display in the cms in a sidebar using a widget
anyone any ideas ?
using this i get the events but it shows from and to i just want the events for that week