ternCal - calendaring plugin for WordPress ™

Events and the WordPress ™ "Loop"


After querying for events you’re ready to do something with them! Click here to read about querying events.

Let’s take a simple query:

<?php $events = $ternCal->events(array(
	'view'		=>	'month',
	'upcoming'	=>	true
)); ?>

This query retrieves from the database the upcoming events for the current month. Let’s say it’s October 12th, 2011. This query retrieves all events that occur in the month of October that start on or after October 12th.

Now that we have queried and found our events, what do we do with them? ternCal returns the events in an array just like WordPress ™’ “get_posts” function. You can read about the “get_posts” function here. At this point we have an array of events that we can loop through to display them to our users. As each theme, designer, programmer and developer is different most likely the technology you use in your active WordPress ™ theme is different. So let’s just talk about the WordPress ™ loop. You can read about the WordPress ™ loop here.

The WordPress ™ loop in essence just takes a list (array in programming speak) of events (which are just WordPress ™ posts) and one at a time moves through them to print data specific to each event to the page.

A standard way to loop through events might look like this:

<?php

//first query for your events
$events = $ternCal->events(array(
	'view'		=>	'month',
	'upcoming'	=>	true
));

//then loop through your events
if($events) {

	foreach((array)$events as $post) {
		setup_postdata($post);
?>
		<div class="post">
			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
			<small><?php gmdate('F jS, Y',$post->start) ?></small>
			<div class="entry"><?php the_content(); ?></div>
			<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
		</div>
<?php
	}
}
?>

Please note that this is an extremely simple version of the WordPress ™ loop. There is much more you’re able to do with ternCal in this loop. In the event that you’re confused by the code above, you should probably either seek assistance or avoid this functionality.


Table of Contents

Home » Documentation » Creating Custom Post Lists of Events » Events and the WordPress ™ "Loop"




Copyright © 2012 Ternstyle LLC. All rights reserved.
site design: ternstyle.us
Lehigh Valley Website Design