• 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 5 replies - 16 through 20 (of 20 total)
  • Here’s another way of doing it. This limits the post content to 254 characters. I use it for displaying featured events:

    <?php
    	query_posts('category_name=Events&eventDisplay=upcoming');
    	$calender = get_cat_ID( 'Events' ); $calender_link = get_category_link( $calender );
    	$the_query = new wp_query('meta_key=_EventStartDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_value&order=ASC');
    
    	while ($the_query->have_posts()) : $the_query->the_post();
    
    ?> 
    
    		<li>
    			<?php
    				$category = get_the_category();
    				$categoryname = $category[1]->cat_name;
    			?>
    			<?php the_title('<div class="event-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" class="' .$categoryname . ' tectip">', '</a></div>'); ?>
    			<div class="event-date">
    				<?php
    					echo the_event_start_date();
    				?>
    			</div>
    				<?php
    					echo substr($post->post_content, 0, 254);
    					echo '<p><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" class="' .$categoryname . ' tectip">... Read More About This Event</a></p>';
    				?>
    		</li>
    <?php
    	$alt = ( empty( $alt ) ) ? ' alt' : '';
    	endwhile; // posts
    ?>

    r3volution11, thanks a lot. Your first block of code worked out great. And you were correct about it not limiting the posts which I was able to resolve by limiting the overall posts in the admin section. Thanks again.

    That’s great, glad to hear.

    I guess it worked out well that I couldn’t get SebAshton’s code to work. ??

    @r3volution11 Thanks for this fix. Your comparison of the event start date meta value vs. the current time enabled me to successfully query past and upcoming events (by changing the meta_compare), whereas the built-in parameter eventDisplay never quite worked.

    Does posts_per_page still not work as you expect it in this context? I changed my value to 1 (to just show the very next or previous event), and it seems to work.

    Thanks again for the fix.

    @amp343 You’re welcome! Glad it proved useful for someone else.

    I’ll have to check truthfully. I went through so many code revisions getting it to work that afterward I didn’t even try resetting posts_per_page and setting the global amount differently.

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