Home › Forums › Calendar Products › Events Calendar PRO › Using Tribe_Get_Events is causing featured images in main calendar to break?
- This topic has 3 replies, 2 voices, and was last updated 8 years, 6 months ago by
Jennifer.
-
AuthorPosts
-
September 20, 2017 at 7:22 am #1351872
tradingbo
ParticipantHi ECP,
Using the following code to create a ‘billboard’ like upcoming event list on our homepage. The code is sourced as per your
https://theeventscalendar.com/knowledgebase/using-tribe_get_events/ link.<?php // Ensure the global $post variable is in scope global $post; // Retrieve the next 5 upcoming events $events = tribe_get_events( array( 'post_status'=>'publish', 'eventDisplay' => 'list', 'posts_per_page' => 6 ) ); // Loop through the events: set up each one as // the current post then use template tags to // display the title and content foreach ( $events as $post ) { setup_postdata( $post ); // This time, let's throw in an event-specific // template tag to show the date after the title! echo " <a href='$post->guid'><li><span>$post->post_title </span></a>"; echo tribe_get_start_date( $post->ID, false, 'j<\s\u\p>S<\/\s\u\p> F Y', "</li>" ); } ?>This is working great, however seems to have messed with the event images in the single-event-photo-view? Event images are displaying correctly on the overall photo view grid layout, however when you choose an event and view it individually they all display a featured image from the same random event?
Is it not ok to use an event loop in multiple places on a site?
Many Thanks,
MSeptember 20, 2017 at 7:56 am #1351896tradingbo
ParticipantApologies managed to resolve issue by reverting to $events as $event in the loop.
Amended code to…<?php // Ensure the global $post variable is in scope global $post; // Retrieve the next 5 upcoming events $events = tribe_get_events( array( 'post_status'=>'publish', 'eventDisplay' => 'list', 'posts_per_page' => 6 ) ); // Loop through the events: set up each one as // the current post then use template tags to // display the title and content foreach ( $events as $event ) { setup_postdata( $event ); // This time, let's throw in an event-specific // template tag to show the date after the title! echo '<li><a><span>'.get_the_title( $event->ID ).'</span></a>'; echo tribe_get_start_date( $event->ID, false, 'j<\s\u\p>S<\/\s\u\p> F Y', "</li>" ); } ?>Thanks
September 20, 2017 at 7:57 am #1351899tradingbo
ParticipantAlso removed <span> as this is now redundant
September 20, 2017 at 4:48 pm #1352343Jennifer
KeymasterHi Michael,
I’m glad to hear you were able to get this resolved, and thanks for posting your solution here for others to see as well!
I’ll go ahead and close out this thread, but please feel free to open a new one if you have any further questions.
Thanks,
Jennifer
-
AuthorPosts
- The topic ‘Using Tribe_Get_Events is causing featured images in main calendar to break?’ is closed to new replies.
