Home › Forums › Calendar Products › Events Calendar PRO › Events Calendar widget: make date link direct to event?
- This topic has 1 reply, 2 voices, and was last updated 9 years, 9 months ago by Barry.
-
AuthorPosts
-
July 18, 2014 at 10:14 am #446004Timothy LindsayParticipant
Hi all,
The Events Calendar widget – when set to list zero events – will turn the dates into links to a page for that day, rather than directly to the event. It makes sense to do it like this, because there may be multiple events on that date, so you need to link to a list for the day in general.
But what if there *is* only one event on that particular day? I’d like to be able to change that link to point direct to the event page.
Has anyone tried this? If so, any code or tips would be appreciated.
Also, Tribe – please consider this a feature request 🙂
July 20, 2014 at 11:00 pm #467433BarryMemberHi!
We welcome any and all feature requests over on our UserVoice – and if the idea has already been submitted you are welcome to upvote it:
In the meantime, if you want to do this as a customization then you can – it should be possible with a little code in your theme’s functions.php file. Though incomplete (this is purely a potential starting point for you) you could do something like this:
/** * Incomplete function that lets you modify the day links for * mini calendar table cells that contain events. * * @param $html * @return mixed */ function minical_custom_links( $html ) { // We only want to modify links! if ( false === strpos( $html, 'href="#"' ) ) return $html; if ( false === strpos( $html, 'data-day' ) ) return $html; // Get the date $matches = array(); $match = preg_match( '#data-day="([0-9\-]{10})"#', $html, $matches ); // Did we find what we were looking for? if ( ! $match || ! isset( $matches[1] ) ) return $html; $date = $matches[1]; // At this point you'll need to weave some additional magic: // you now have a date ($date) that you know contains events - // you'll need to query to see how many it contains and either // return the original $html unmodified or else link directly // to the single event it contains ... good luck! return $html; // Leaving this in place so as not to break things } // Hook up our custom calendar widget links function add_filter( 'tribe_events_the_mini_calendar_day_link', 'minical_custom_links' );
Of course there’s some work for you to do there in determining how many events a given day contains, but it should give you the basic idea.
Thanks – and good luck 🙂
-
AuthorPosts
- The topic ‘Events Calendar widget: make date link direct to event?’ is closed to new replies.