• Recently I had to design a theme that had required calander and to show 5 upcoming events/items outside of the sidebar.

    The Events Calendar (TEC) didn’t seem to support this out the box and with use of wp_query I was able to solve the problem, now I’m sharing it with you so if can be of help to others:

    <div>
    	<?php $calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );?>
    	<h2>Coming Up</h2>
    	<?php global $spEvents;
    	$spEvents->loadDomainStylesScripts();?>
    	<div id="tec-content main" class="upcoming">
    		<div id="tec-events-loop" class="tec-events post-list clearfix">
    	<?php
    		$todaysDate = date('Y-m-d G:i:s');
    		$cal_query = new wp_query('category_name=Events&posts_per_page=5&meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC'); ?>
    	<?php while ($cal_query->have_posts()) : $cal_query->the_post(); ?>
    
    		<div id="post-<?php the_ID() ?>" class="tec-event post clearfix<?php echo $alt ?>">
    		<div style="clear:both;"></div>
    			<?php the_title('<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></h2>'); ?>
    									<!-- End tec-event-entry -->
    		</div> <!-- End post -->
    	<?php $alt = ( empty( $alt ) ) ? ' alt' : '';?>
    		<?php endwhile; // posts ?>
    	</div>
    </div>
    			</div>
    
    		<span id="more"><a href="<?php echo $calender_link;?>">more &raquo;</a></span>
    		</div>

    Do with it what you will, if you want to show more/less posts alter the wp_query.

    Hope the above snippet helps someone

    https://www.ads-software.com/extend/plugins/the-events-calendar/

Viewing 15 replies - 1 through 15 (of 20 total)
  • This helped me out a lot! Thanks so much.

    muhammad.yuqi

    (@muhammadyuqi)

    in my site not running, how? i mean blank just “Coming Up”

    Thanks SebAshton! Been playing with other pieces of code and came across yours which worked perfectly! Fantastic!

    I also added a line to show the event date and ended up with:

    <div>
    	<?php $calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );?>
    
    	<?php global $spEvents;
    	$spEvents->loadDomainStylesScripts();?>
    	<div id="tec-content main" class="upcoming">
    		<div id="tec-events-loop" class="tec-events post-list clearfix">
    	<?php
    		$todaysDate = date('Y-m-d G:i:s');
    		$cal_query = new wp_query('category_name=Events&posts_per_page=5&meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC'); ?>
    	<?php while ($cal_query->have_posts()) : $cal_query->the_post(); ?>
    
    		<div id="post-<?php the_ID() ?>" class="tec-event <?php echo $alt ?>">
    		<div style="clear:both;"></div>
    			<ul><?php the_title('<div class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></div>'); ?>
               <?php echo the_event_start_date( null, false ); ?></ul>
    			<!-- End tec-event-entry -->
    		</div> <!-- End post -->
    	<?php $alt = ( empty( $alt ) ) ? ' alt' : '';?>
    		<?php endwhile; // posts ?>
    	</div>
    </div>
    			</div>

    You can see it working here: https://darwinhub.com/

    As for muhammad.yuqi, can you be a bit more descriptive and I’ll see if there is any way I can help…

    Hi Seb and Ciaran,

    Thanks for the code….working nicely….just one issue. I have New Year’s Eve events with event date as December 31st, and I have placed your code in my homepage template script….right now, it is December 30th where I am located…and my WordPress time settings are correct also…. however, the homepage is only displaying upcoming events starting January 1st….it is acting as if December 31st events are not “upcoming”….

    Any fix for this? Is there a way to tell this script you’ve provided to keep today’s events in “upcoming” until the event date has passed?

    Thanks for your help in advance

    THANK YOU SO MUCH!

    This was killing me.

    Hey guys, this is awesome, thank you so much.

    Problem though: It’s not working correctly for me. It’s only listing one event when there are 8 upcoming. Are there any extra bits of code that you both may have forgotten to mention?

    Here is my code:

    <div>
                        	<?php $calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );?>
                            <?php global $spEvents;
                            $spEvents->loadDomainStylesScripts();?>
                            <div id="tec-content main" class="upcoming">
                                <div id="tec-events-loop" class="tec-events post-list clearfix">
                            <?php
                                $todaysDate = date('Y-m-d G:i:s');
                                $cal_query = new wp_query('category_name=Events&posts_per_page=5&meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC'); ?>
                            <?php while ($cal_query->have_posts()) : $cal_query->the_post(); ?>
                                <div id="post-<?php the_ID() ?>" class="tec-event <?php echo $alt ?>">
                                <div style="clear:both;"></div>
                                    <ul><?php the_title('<div class="event-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></div>'); ?>
                                   <?php echo the_event_start_date( null, false ); ?></ul>
                                    <!-- End tec-event-entry -->
                                </div> <!-- End post -->
                            <?php $alt = ( empty( $alt ) ) ? ' alt' : '';?>
                                <?php endwhile; // posts ?>
                            </div>
                        </div>
                        </div>

    I’ve figured out that for some reason the script is only showing one sub-category of the Events category oddly enough. If I put all of the events in that sub-category it works but of course that doesn’t work well at all.

    Well my fix was actually just to use query_posts and I limited the amount of events listed by setting the amount of posts to be displayed in Admin. I then set another query_posts to a different posts_per_page limited in loop.php to display more regular posts.

    Thanks so much SebAshton and ciaranm! What a great solution. What would I need to do to revise it to show the full dates for events…whether they are just one day or 2 weeks long? I really appreciate the help.

    Also, I have an event that starts Feb. 1 and ends April 15. Is there a way it can stay on my list until the end date has past? Thanks again.

    Just like there’s the_event_start_date there’s also the_event_end_date

    Hi I got this working, and I’m trying to add the post thumbnail with but I keep syntax error? anyone know a fix for this?

    Hi, Ive been trying out this code on 3.1 and I am getting 0 results.
    Any idea if something might be different?

    When I remove
    &meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value

    From the query string I get results, but obviously that is exactly the utility of this code.
    I wonder that wp is smart enough to parse a date with meta_compare, but apparently it has worked for other people here.

    Thanks,
    alvar

    ps, originally I thought that using this in a query string:
    &cat=&eventDisplay=upcoming
    as listed on the plugin page, would produce the same results, but I get the following error:

    Notice: Undefined index: displayEventsOnHomepage in /Users/alvar/Sites/DS/forge/trunk/wp/wp-content/plugins/the-events-calendar/template-tags.php on line 13
    
    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND wp_term_taxonomy.taxonomy = 'category' AND wp_posts.post_status = 'publis' at line 9]
    SELECT wp_posts.*, d1.meta_value as EventStartDate , d2.meta_value as EventEndDate FROM wp_posts LEFT JOIN wp_postmeta as d1 ON(wp_posts.ID = d1.post_id) LEFT JOIN wp_postmeta as d2 ON(wp_posts.ID = d2.post_id) LEFT JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE wp_term_taxonomy.term_id = AND wp_term_taxonomy.taxonomy = 'category' AND wp_posts.post_status = 'publish' AND d1.meta_key = '_EventStartDate' AND d2.meta_key = '_EventEndDate' AND ( d1.meta_value > "2011-03-16 15:22:01" OR ( d1.meta_value < "2011-03-16 15:22:01" AND d2.meta_value > "2011-03-16 15:22:01" ) ) ORDER BY d1.meta_value ASC LIMIT 10

    I recently upgraded wp 3.1 and now the upcoming events are not showing at all… Anyone figure this out? Here is the code I’m using:

    <ul>
                  <?php $calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );?>
                  <?php global $spEvents;
    	$spEvents->loadDomainStylesScripts();?>
                  <?php
    		$todaysDate = date('Y-m-d G:i:s');
    		$cal_query = new wp_query('category_name=Events&posts_per_page=3&meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC'); ?>
                  <?php while ($cal_query->have_posts()) : $cal_query->the_post(); ?>
                  <li><?php echo the_event_start_date( null, false ); ?><br />
                    <?php the_title('<a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a>'); ?>
                  </li>
                  <!-- End tec-event-entry -->
    
                  <?php $alt = ( empty( $alt ) ) ? ' alt' : '';?>
                  <?php endwhile; // posts ?>
                </ul>

    Any help would be awesome.

    Hey guys. I actually had to do a variation of SebAshton’s code from the beginning (re: pre 3.1) to get it to work with my sites.

    Here’s what I used:

    <div id="e-1">
                    	<?php
    						query_posts('category_name=Events&eventDisplay=upcoming&posts_per_page=5');
    					?>
                        <div>
                            <?php $calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );?>
    
                            <?php global $spEvents;
                            $spEvents->loadDomainStylesScripts();?>
                            <div id="tec-content main" class="upcoming">
                                <div id="tec-events-loop" class="tec-events post-list clearfix">
                            <?php
    							date_default_timezone_set('America/New_York');
                                $todaysDate = date('Y-m-d G:i:s');
                                $cal_query = new wp_query('category_name=Events&posts_per_page=5&meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC'); ?>
                            <?php while ($cal_query->have_posts()) : $cal_query->the_post(); ?>
                                <div id="post-<?php the_ID() ?>" class="tec-event <?php echo $alt ?>">
                                    <ul>
    									<?php
    										$tit = the_title('','',FALSE);
    										echo '<div class="event-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '">' . substr($tit, 0, 50) . '</a></div>';
                                    		echo the_event_start_date();
                                        ?>
                                    </ul>
                                </div>
                            <?php $alt = ( empty( $alt ) ) ? ' alt' : '';?>
                                <?php endwhile; // posts ?>
                            </div>
                        </div>
                        </div>
                        <span id="more"><a href="<?php echo $calender_link;?>">View More Events &raquo;</a></span>
                    </div>

    I’m going off of memory and to be honest I don’t believe this code properly limits the posts so I limited the overall post amount in the WP admin settings and then added a query_posts in the loop to change the quantity for regular posts.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: The Events Calendar] Want to show 5 upcoming events outside of the sidebar’ is closed to new replies.