WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: The Events Calendar] Want to show 5 upcoming events outside of the sidebar (21 posts)

  1. SebAshton
    Member
    Posted 4 years ago #

    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

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. kpetrowski
    Member
    Posted 4 years ago #

    This helped me out a lot! Thanks so much.

  3. muhammad.yuqi
    Member
    Posted 3 years ago #

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

  4. ciaranm
    Member
    Posted 3 years ago #

    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: http://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...

  5. brianj
    Member
    Posted 3 years ago #

    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

  6. jrgreenfield1
    Member
    Posted 3 years ago #

    THANK YOU SO MUCH!

    This was killing me.

  7. r3volution11
    Member
    Posted 3 years ago #

    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>
  8. r3volution11
    Member
    Posted 3 years ago #

    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.

  9. r3volution11
    Member
    Posted 3 years ago #

    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.

  10. cyberchameleon
    Member
    Posted 3 years ago #

    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.

  11. cyberchameleon
    Member
    Posted 3 years ago #

    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.

  12. r3volution11
    Member
    Posted 3 years ago #

    Just like there's the_event_start_date there's also the_event_end_date

  13. yojames
    Member
    Posted 3 years ago #

    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?

  14. alvarix
    Member
    Posted 3 years ago #

    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
  15. ryan12345
    Member
    Posted 3 years ago #

    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.

  16. r3volution11
    Member
    Posted 3 years ago #

    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.

  17. r3volution11
    Member
    Posted 3 years ago #

    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
    ?>
  18. ryan12345
    Member
    Posted 3 years ago #

    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.

  19. r3volution11
    Member
    Posted 3 years ago #

    That's great, glad to hear.

    I guess it worked out well that I couldn't get SebAshton's code to work. :)

  20. amp343
    Member
    Posted 3 years ago #

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

  21. r3volution11
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic