Home › Forums › Calendar Products › Events Calendar PRO › Get a link of the most recent event(single event)
- This topic has 8 replies, 3 voices, and was last updated 9 years, 4 months ago by
Woong.
-
AuthorPosts
-
January 4, 2017 at 8:04 am #1213136
Woong
ParticipantHi, I am working with Modern Tribe The Events Calendar Pro. I am working in Version 4.3.3 Calendar Pro, and 4.3.5 Calendar.
I’m just looking for how to get a link of the most recent single event page, so that I can add the link to my top navigation menu.
Unfortunately, everytime a new event is added, I have to change the link on the menu.
Is there any way to solve this?
If so, please let me know. thanks.
January 4, 2017 at 2:23 pm #1213467Nico
MemberHey Woong,
Thanks for getting in touch with us!
Unfortunately there’s no such a link available to add to a menu. Maybe you can create a page that redirects to the newest event single page? In this case you would have a fixed link (like http://sitename/latest-event) and with a snippet that page could redirect to the newest event. Does that makes sense to you?
Please let me know about it and I’ll help you out with the snippet,
Best,
NicoJanuary 4, 2017 at 4:47 pm #1213508Woong
ParticipantHi Nico,
Thank you very much for the prompt reply.That is one of the ways I thought, but I could not find that.
That makes sense!How can I make the newest event page?(with existing single event template?)
Thanks!
-
This reply was modified 9 years, 4 months ago by
Woong.
January 5, 2017 at 1:10 pm #1214009Nico
MemberYou are welcome Woong! Thank YOU for following up ๐
How can I make the newest event page?(with existing single event template?)
The idea I was suggesting was to create a WordPress standard page from the admin area, as a placeholder. For example I created a page called ‘Next upcoming event’, then with the following snippet (past it in your theme’s (or child theme’s) functions.php file) when the page is viewed it will redirect users to the next upcoming event:
/* Tribe, redirect page to the next upcoming event */
function tribe_redirect_to_next_event ( ) {// bail if not the most recent event page
// CHANGE THE SLUG FOR THE ONE IN YOUR SITE
if ( !is_page('next-upcoming-event') ) return;// retrieve the next upcoming event
$event = tribe_get_events( array(
'posts_per_page' => 1,
'start_date' => date( 'Y-m-d H:i:s' )
) );// bail if no upcoming event
if ( empty($event) ) return;// redirect
wp_redirect( tribe_get_event_link( $event[0]->ID ) );
exit;
}
add_action( 'wp', 'tribe_redirect_to_next_event' );
Please give this a try and let me know if it works for you,
Best,
NicoJanuary 8, 2017 at 10:05 am #1214872Woong
ParticipantThanks, Nico.
It works well!
But, I wonder whether the solution make some performance issues.
Because whenever people connect our website, there must be redirections right?
I don’t think it’s a huge thing, but I’m just curious about that.Regards,
Woong.January 9, 2017 at 10:04 pm #1215624Nico
MemberYou are welcome Woong! Stoked to hear this worked for you ๐
… whenever people connect our website, there must be redirections right?
Well not really, the first part of the snippet check if the current page is the correct one, and in that case it makes the redirect. If the user is viewing any other pages there won’t be any redirects.
Have you noticed any slowdowns? Have you changed the page slug for the correct one?
Please let me know about it,
Best,
NicoJanuary 11, 2017 at 6:46 pm #1217116Woong
ParticipantHi Nico,
Never noticed any slow downs, actually but just curious about that.
Thanks for your help.Best,
Woong.January 12, 2017 at 10:29 am #1217547Nico
MemberPerfect! Thanks for confirming Woong!
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.
Best,
Nico -
This reply was modified 9 years, 4 months ago by
-
AuthorPosts
- The topic ‘Get a link of the most recent event(single event)’ is closed to new replies.
