Home › Forums › Calendar Products › Events Calendar PRO › How to customize the upcoming events loop
- This topic has 12 replies, 3 voices, and was last updated 10 years, 2 months ago by
Support Droid.
-
AuthorPosts
-
November 9, 2015 at 8:44 pm #1023577
Christian
ParticipantHello!
I am using The Events Calendar plugin to display calendar events on an accounting website. The trick is that the client wants the events that fall on the same day to be listed together. And, if possible, to only show the upcoming 2 months. For example,
Nov. 10, 2015
Accelerated payroll deductionsNov. 15, 2015
Regular payroll deductionsNov. 20, 2015
Canada Child Tax BenefitNov. 30, 2015
Corporate tax installments
Corporate tax returns
Universal Child Care BenefitI was able to create a loop that shows my events, but they are all shown individually with the date for each:
<?php query_posts(array( 'post_type' => 'tribe_events' ) ); while (have_posts()) : the_post(); $url = esc_url( get_permalink( tribe_get_venue_id( $post->ID))); ?> <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3> <p><?php echo tribe_get_start_date($post->ID, true, $format = 'F j, Y - l' );?><br> <?php echo tribe_get_venue_link()?></p> <?php endwhile;?>So it outputs:
Accelerated payroll deductions
November 10, 2015 – TuesdayRegular payroll deductions
November 15, 2015 – SundayCanada Child Tax Benefit
November 20, 2015 – FridayAnd so on! Can you please help me with this loop so I can show my events grouped by date, and possibly have a function that shows automatically the next two months’ worth of events?
Thanks!!!
November 10, 2015 at 4:22 pm #1023981Brook
ParticipantHowdy Christian,
I can definitely help you here. Just to be up front with customizations like this we can’t provide exact code, but definitely guidance on how to build/write it.
The simplest way to do this would probably be to initialize a variable outside the event loop called something like $current_day. Then within the loop you will check to see if the current_day is set to equal the tribe_get_start_date() of your event. If it’s not, output a heading listing the day and set current_day to tribe_get_start_date(). Now as it loops through events it will only output a new heading when the start date has changed. Presto!
As far as how to query for 2 months of upcoming events, checkout tribe_get_events() if you have not already. The documentation I linked to there event includes some examples on doing queries by date!
Does that all make sense? Will that work for you? Please let me know.
Cheers!
– Brook
November 17, 2015 at 3:51 pm #1027205Christian
ParticipantHi Brook!
Thanks! I was able to almost get it to work. The only issue is that the recurring events aren’t showing in the loop. Is there something else I need to take into account to show all the recurring events within that period?
Thanks!
November 17, 2015 at 9:57 pm #1027283Brook
ParticipantHowdy Christian,
That’s interesting. I can’t think of anything extra you should be doing. Would you mind sharing the code you are trying with us? Perhaps something will pop out as the cause.
– Brook
November 19, 2015 at 12:44 pm #1028220Christian
ParticipantHi Brook!
Sure! Here is the code that I have:
<?php $date = getdate(); //Retrieve date 2 months down the road $date = new DateTime("+2 months"); $date = $date->format('YYYY-mm-dd'); //Query posts within the 2 month window query_posts(array( 'post_type' => 'tribe_events', 'posts_per_page' => -1, 'end_date'=>date('Y-m-d', strtotime('+60 days'))) ); //Initialize variable $currentDate = ''; if (have_posts()) : while (have_posts()) : the_post(); $url = esc_url( get_permalink( tribe_get_venue_id( $post->ID))); ?> <?php //Grab current event date $eventDate = tribe_get_start_date($post->ID, true, $format = 'F j, Y' ); //If the current event date does not match the variable, print the date heading if ($currentDate != $eventDate){ echo "</ul><h3>".$eventDate."</h3><ul>"; } //Update the date variable to the most recent event $currentDate = $eventDate; ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php endif; ?>It seems to only be outputting the first instance of a recurring event. The link to the site I have it working is here (The Mark your calendar section):
http://104.131.139.81/I hope you can spot the problem 🙂
Thanks!-
This reply was modified 10 years, 6 months ago by
Christian.
November 19, 2015 at 12:45 pm #1028223Christian
Participant<?php $date = getdate(); //Retrieve date 2 months down the road $date = new DateTime("+2 months"); $date = $date->format('YYYY-mm-dd'); //Query posts within the 2 month window query_posts(array( 'post_type' => 'tribe_events', 'posts_per_page' => -1, 'end_date'=>date('Y-m-d', strtotime('+60 days'))) ); //Initialize variable $currentDate = ''; if (have_posts()) : while (have_posts()) : the_post(); $url = esc_url( get_permalink( tribe_get_venue_id( $post->ID))); ?> <?php //Grab current event date $eventDate = tribe_get_start_date($post->ID, true, $format = 'F j, Y' ); //If the current event date does not match the variable, print the date heading if ($currentDate != $eventDate){ echo "</ul><h3>".$eventDate."</h3><ul>"; } //Update the date variable to the most recent event $currentDate = $eventDate; ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php endif; ?>November 19, 2015 at 12:47 pm #1028224Christian
ParticipantI edited my previous post, but it seemed to delete what I wrote. I meant to show you the link to where I have this code: http://104.131.139.81 (Mark your calendar section on sidebar)
I hope you can spot what the issue is!
Thanks!
November 19, 2015 at 10:05 pm #1028362Brook
ParticipantThank you for sharing that. You have an awesome looking site. It’s neat to see how you’ve customized things removing what you don’t need.
I ran your exact code on my website and it showed recurring events amongst the rest. Are you certain your recurring events fit within the criteria specified? The end date being within 60 days. The post would have to be published and public.
- Brook
November 19, 2015 at 10:06 pm #1028363Brook
ParticipantOn, could you maybe share a direct link to an event that’s not showing if the above doesn’t help?
- Brook
November 20, 2015 at 9:05 am #1028681Christian
ParticipantHi Brook!
So 2 examples of recurring events would be:
http://104.131.139.81/calendar/corporate-tax-installments/all/ and
http://104.131.139.81/calendar/corporate-tax-returns/all/They should repeat at the end of every month.
THanks!
November 23, 2015 at 7:57 pm #1029906Christian
ParticipantHi Brook,
Hope you have a chance to look at the issue soon! 🙂
Thanks!
November 23, 2015 at 11:44 pm #1029923Brook
ParticipantHowdy Christian,
I am sorry we were out for the weekend. But I am back now! Thanks for sharing the link.
I actually am seeing those recurring events on your website. Tax installments and returns on the 30th. However, your site does appear to have the setting “Show only the first instance of each recurring event” checked. When this is checked you will only see the first occurrence as we are now. Perhaps you wish to uncheck it and hit Save? It can be found in WP-Admin > Events > Settings, under the label “Recurring event instances”.
Does that work?
Cheers!
– Brook
February 18, 2016 at 8:31 am #1075764Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
This reply was modified 10 years, 6 months ago by
-
AuthorPosts
- The topic ‘How to customize the upcoming events loop’ is closed to new replies.
