Home › Forums › Calendar Products › Events Calendar PRO › Linking to single event view from list items in tribe_get_events
- This topic has 6 replies, 2 voices, and was last updated 11 years, 4 months ago by
Geoff.
-
AuthorPosts
-
December 29, 2014 at 10:54 am #926369
Kate
ParticipantI am using tribe_get_events to display a list of 4 upcoming events on a homepage. I am using code found at this knowledgebase page. It basically works, spitting out the 4 event titles. But I can’t figure out how to get each title to link to its single event page. Can someone point me in the right direction?
December 29, 2014 at 1:22 pm #926427Geoff
MemberHi there, Kate! Thanks for getting in touch and welcome to the forums. We hope you’ve been enjoying the plugins so far. 🙂
Good question. If you look at the loop you created for the query you set up, you should be able to locate where the Event Title is being called, then wrap it in a link tag that uses tribe_get_event_link(). For example:
<a href="<?php echo tribe_get_event_link() ?>" title="<?php the_title() ?>" rel="bookmark"> <?php the_title() ?> </a>It may be a little different for you depending on how you set up the loop and you might have to fiddle with it, but this should at least get you pointed in the right direction.
Cheers!
GeoffJanuary 5, 2015 at 10:03 am #928865Geoff
MemberHi there, Kate! Just checking in to see if there’s been any update or if you still need any assistance on this one–please let me know. 🙂
Cheers!
GeoffJanuary 5, 2015 at 10:25 am #928881Kate
ParticipantThanks for circling back, I hadn’t seen your first reply. Unfortunately it doesn’t help me. Here is the code I am using to pull the next 4 events into a simple list on the homepage:
<?php $events = tribe_get_events( array( 'posts_per_page' => 4, 'start_date' => new DateTime() ) ); // Loop through the events, displaying the title foreach ( $events as $event ) { echo "<li> $event->post_title </li>"; } ?>I adapted this code from this knowledge base article.
Since the title is being echoed in PHP code, if I add a link the way you suggested in your reply, it causes an error that makes the homepage load blank white.
How can I adapt my code to link the post titles to the single events? Thanks!
January 5, 2015 at 1:45 pm #928987Geoff
MemberHi there, Kate! Thanks for following up. 🙂
Sorry the example I provided didn’t do the trick. Ultimately, it will come down to how you format your code, but you need to echo the permalink of the event post and wrap that around the event post title.
Here’s another example of how you can do that. You can see where the_permalink() was used to output the URL and how that URL wraps around the title. Give that a shot and hopefully that provides a better direction for you.
https://gist.github.com/jo-snips/3427287
Cheers!
Geoff-
This reply was modified 11 years, 4 months ago by
Geoff.
January 6, 2015 at 8:39 am #929367Kate
ParticipantThis reply is private.
January 6, 2015 at 9:08 am #929390Geoff
MemberRad, I’m glad that helped out! Yeah, using tribe_get_events() can be a little tricky and, admittedly, that tutorial can use a little refresh–thanks for pointing it out.
I’ll go ahead and close this thread but please feel free to hit us up with a new one if anything else pops up. We’d be happy to help. 🙂
Cheers!
Geoff -
This reply was modified 11 years, 4 months ago by
-
AuthorPosts
- The topic ‘Linking to single event view from list items in tribe_get_events’ is closed to new replies.
