events by month
-
browse events by month automatically one page?
for example.:
June
1 event
2 event
…July
1 event
2 event
…is good for the short code or template files.
thank you for your help.
-
You want to display the events on one page, grouped by month?
Simply query all events and then loop through them. Keep track of the ‘current month’ the event is in:
$event_month = eo_get_the_start( 'Y-m');(see codex) and when the month changes, print the name of the month and start a new second:
$event_month = eo_get_the_start( 'Y-m'); if( $current_month != $event_month ){ echo '</div>'; //end section echo '<div>'; //new section echo '<h2>'.eo_get_the_start( 'F Y').'<h2>'; //Print month $current_month = eo_get_the_start( 'Y-m') }I’ll leave the details for handling the first and last section to you :).
yes, nice, thank you!
similar grouping of the year as well?
edit: oh, yes! 😀
<?php $event_year = eo_get_the_start( 'Y'); if( $current_year != $event_year ){ echo '</div>'; //end section echo '<div>'; //new section echo '<h2>'.eo_get_the_start( 'Y').'<h2>'; //Print year $current_year = eo_get_the_start( 'Y'); }?>For those who wanted pagination by year/month/day (for example, all events in a given year on one page, and the next page points to the following year) – see this thread http://wordpress.org/support/topic/pagination-by-year?replies=3
thanks.
there’s a problem with the html output.
<div><h2>2011</h2><h2> </h2></div> <div><h2>június</h2><h2> <article id="post-21" class="post-21 event type-event status-publish hentry"> <header class="entry-header"> <h1 class="entry-title" style="display: inline;"> <a href="http://localhost/event/events/event/fghgf/">fghgf</a> </h1> <div class="event-entry-meta"> <!-- Output the date of the occurrence--> <time itemprop="startDate" datetime="2011-06-16">2011 június 16</time> <!-- Display event meta list --> <ul class="eo-event-meta" style="margin:10px 0px;"><li><strong>Kategóriák:</strong> <a href="http://localhost/event/events/category/mozi/" rel="tag">mozi</a></li></ul> <!-- Event excerpt --> <p>hgfhfghfghfg</p> </div><!-- .event-entry-meta --> <div style="clear:both;"></div> </header><!-- .entry-header --> </article><!-- #post-21 --> </h2></div>the archive-event.php looks like me:
...etc <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php $event_year = eo_get_the_start( 'Y-m'); if( $current_year != $event_year ){ echo '</div>'; //end section echo '<div>'; //new section echo '<h2>'.eo_get_the_start( 'Y').'<h2>'; //Print month $current_year = eo_get_the_start( 'Y-m'); }?> <?php $event_month = eo_get_the_start( 'Y-m'); if( $current_month != $event_month ){ echo '</div>'; //end section echo '<div>'; //new section echo '<h2>'.eo_get_the_start( 'F').'<h2>'; //Print month $current_month = eo_get_the_start( 'Y-m'); }?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> ...etcsomething is wrong with the new part.
thanks for your help!
you are not closing your h2 tags.
Change both occurrences of:echo '<h2>'.eo_get_the_start( 'Y').'<h2>'to:
echo '<h2>'.eo_get_the_start( 'Y').'</h2>'and you should be good to go.
@troobles oh my… sorry, thank you!
one more thing:
grouped by year, and within a month?
how to?thanks!
Not sure what you mean – if you want to have ‘{Year}’ and ‘{Month}’ headings:
E.g.:
2012 Dec -Event A 2013 Jan -Event A -Event B Feb -Event cThen just use the simliar logic of checking when the year / month changes.
yes, I thought.
The topic ‘events by month’ is closed to new replies.