Home › Forums › Calendar Products › Events Calendar PRO › Mini widget date link direct to event (only have 1 event each day)
- This topic has 4 replies, 3 voices, and was last updated 9 years, 3 months ago by
Erik.
-
AuthorPosts
-
January 13, 2017 at 6:13 am #1218019
Erik
ParticipantHello,
First of all, many thanks for great plugin and great support.
I’m not a great coder, so I’m checking here for suggestion – or possible already available ideas – it might be an old problem.
In my calendar I only have 1 event each day (mainly start & end date events) – and when I click on the mini calendar-widget I need to do 2 clicks to get into the information about the event, since the first click shows the available events for the day – and in my case, only ever 1.
I would like a little help figuring out how to make the mini widget calendar go straight to the event on a click. Hopefully something others have asked about before, so there might be a suggestion ready.
This thread has the same problem, although from 2014 and with mixed number of events each day – I only have one.
Support there suggests this code, unfinished:
/**
* 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' );A great start, but since I’m not doing much other than dabble in the code, I’m having too much problem with the part left open.
$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
So my question is really, if there is someone that might have found a solution to this since 2014, or if support might be able to add or hint to some of that code supposed to be put in there to make the date link direct me straight to the only event for the day.
I have no need to find a query that checks how many events it contains, I pretty much just need the code to make it into a straight link for that event.Much to ask, I’m sure, but I’m at a loss for ideas – and feel that with this code above I am close.
Thank you so much for any answer, in advance.
πJanuary 16, 2017 at 8:32 am #1219034Nico
MemberHi there Erik,
Thanks for getting in touch with us! Although we cannot provide much help with customizations, this one is mostly done so I’ll just add the missing step π
Try pasting this snippet in your theme’s (or child theme’s) functions.php file, it should make the link go directly to the event:
/* Tribe, minical link directly to first the first event of the day */
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];// get event
$events = tribe_get_events( array( 'posts_per_page' => 1, 'start_date' => date( $date ) ) );if ( !empty($events) ) {
$event_link = tribe_get_event_link( $events[0]->ID );
$day = tribe_events_get_current_month_day();
$html = '' . $day['daynum'] . '';
}return $html;
}// Hook up our custom calendar widget links function
add_filter( 'tribe_events_the_mini_calendar_day_link', 'minical_custom_links' );
It might slowdown things a bit, but hopefully not too much. Give it a try and let me know if it works for you,
Best,
NicoJanuary 16, 2017 at 10:57 pm #1219451Erik
ParticipantHey – it worked!
Thanks for the assistance, the code you added did the trick – and I wouldn’t have figured that one out on my own. Huge thanks, you’ve just completed a major project for me.
For anyone looking for an answer to this – the code above worked for me.
In my browser the =>-part didn’t turn into =>, so when I changed that it worked out.'posts_per_page' => 1PS: Didn’t slow things down at all!
January 17, 2017 at 9:37 am #1219697Nico
MemberThanks for confirming and for the heads-up about the formatting issue! It’s fixed now π
Iβll go ahead and close out this thread, but if you need help with anything else please donβt hesitate to create a new one and we will be happy to assist you.
Glad to be of service,
Nico -
AuthorPosts
- The topic ‘Mini widget date link direct to event (only have 1 event each day)’ is closed to new replies.
