How to customize the upcoming events loop

Home Forums Calendar Products Events Calendar PRO How to customize the upcoming events loop

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1023577
    Christian
    Participant

    Hello!

    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 deductions

    Nov. 15, 2015
    Regular payroll deductions

    Nov. 20, 2015
    Canada Child Tax Benefit

    Nov. 30, 2015
    Corporate tax installments
    Corporate tax returns
    Universal Child Care Benefit

    I 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 – Tuesday

    Regular payroll deductions
    November 15, 2015 – Sunday

    Canada Child Tax Benefit
    November 20, 2015 – Friday

    And 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!!!

    #1023981
    Brook
    Participant

    Howdy 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

    #1027205
    Christian
    Participant

    Hi 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!

    #1027283
    Brook
    Participant

    Howdy 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

    #1028220
    Christian
    Participant

    Hi 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.
    #1028223
    Christian
    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; ?>
    #1028224
    Christian
    Participant

    I 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!

    #1028362
    Brook
    Participant

    Thank 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
    #1028363
    Brook
    Participant

    On, could you maybe share a direct link to an event that’s not showing if the above doesn’t help?

    • Brook
    #1028681
    Christian
    Participant

    Hi 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!

    #1029906
    Christian
    Participant

    Hi Brook,

    Hope you have a chance to look at the issue soon! 🙂

    Thanks!

    #1029923
    Brook
    Participant

    Howdy 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

    #1075764
    Support Droid
    Keymaster

    This 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.

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘How to customize the upcoming events loop’ is closed to new replies.