Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Forked from stephenh1988/venue-page.php
Last active December 13, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/4988324 to your computer and use it in GitHub Desktop.
Save stephenharris/4988324 to your computer and use it in GitHub Desktop.
A page template that lists venues with Event Organiser
<?php
/**
* Template Name: Venue Archive
* Description: A page template that lists venues with Event Organiser. Just a simple example of what
* you can do.
*
* Instructions:
* 1. Create a page template for theme (it will probably need to be different from this template)
* 2. Ensure it has a template name (see "Temple Name:" above).
* 3. Create a page, selecting this template of the page.
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
//Set up query variables
$total = wp_count_terms( 'event-venue' );
$per_page = 5;
$total_pages = ceil( $total / $per_page );
$page = max( 1, (int) get_query_var( 'paged' ) );
$venues = eo_get_venues( array(
'offset' => ( $page - 1 ) * $per_page,
'number' => $per_page
) );
if( $venues ):
foreach( $venues as $venue ):
$venue_id = (int) $venue->term_id;
printf('<article id="venue-%d">', $venue_id );
/* Display venue name and address */
echo '<header class="entry-header">';
printf('<h1> %s </h1>', eo_get_venue_name($venue_id) );
$address = array_filter(eo_get_venue_address($venue_id));
echo implode(', ',$address);
echo '</header>';
/* Display venue description & map */
echo '<div class="entry-content">';
echo eo_get_venue_description($venue_id);
echo eo_get_venue_map($venue_id);
/* Display next 5 events */
$events = eo_get_events(array(
'numberposts'=>5,
'event_start_after'=>'now',
'tax_query'=>array(array(
'taxonomy'=>'event-venue',
'field'=>'id',
'terms'=>array($venue_id),
))
));
if( $events ){
echo '<h2> Next 5 events </h2>';
echo '<ul>';
foreach ($events as $event ){
printf('<li> %s on %s </li>', get_the_title($event->ID), eo_get_the_start('jS F Y', $event->ID,null,$event->occurrence_id));
}
echo '</ul>';
}
echo'</div>';
echo'</article>';
endforeach;
//Pagination
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $page,
'total' => $total_pages,
) );
endif;?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment