Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi Stinoga,
    The events category is a custom taxonomy with slug ‘event-category’, so you can use the usual WordPress functions for it:

    get_the_term_list – displays the event’s category terms as a list.

    get_the_terms – returns the event’s as an array.

    For instance, when in the loop:
    $categories_list = get_the_term_list( get_the_ID(), 'event-category', '', ', ','');
    will give you the list of the category terms, seperated by commas which you can then simply echo.

    Thread Starter stinoga

    (@stinoga)

    Thanks for the reply Stephen. That is actually what I’ve been doing, although that seems to bring back a full list of the custom taxonomies. I would like to just return the event-category that is selected.

    In my example, I am trying to sort the returned events under year headers, like so:

    2011:
    eventa
    eventb

    2012:
    eventc

    So when I write out the posts in the loop, i’d like to be able to show only posts using the event category of 2011, 2012, etc.

    What do you think?

    Thanks for the help!
    _Rob

    When used inside the loop:
    get_the_terms(get_the_ID(), 'event-category')
    will return an array of taxonomy-term objects associated with that post. The get_the_term_list will display that array as a list (you can see it in action in the default single-event template).

    Unfortunately, what you’re trying to do isn’t particularly easy with WordPress – and it comes down to how it deals with taxonomies. (See this question).

    However, since events are sorted by date you could achieve this by editing the templates. For instance, define a variable $year to be the year of the first returned event, and inside the loop check the year of the event to be displayed (you can use eo_get_the_start and set the format to return just the year). When the year matches the $year variable, simply display the event and if it does not, update $year to match it, display a header (e.g. 2012) and then display the event.

    Hope that helps!

    Thread Starter stinoga

    (@stinoga)

    Awesome. Thanks for all the help on this Stephen! I’ll make sure to send you a link when this project is live! Here is the final result:

    <article id="showList">
    				<?php
    					//instantiate the first year variable, to be used later
    					$firstYear = "";
    				?>
    				<?php while ( have_posts() ) : the_post(); ?>
    					<?php
    						//grab the year attached to each post
    						$currentYear = eo_get_the_start("Y", $post->ID);
    
    						//check if the current year is equal to the year from the previous event,
    						//if it is, set the firstyear to currentyear, and echo the data as the data header
    						if ($firstYear != $currentYear) {
    							$firstYear = $currentYear;
    							echo "<header class='entry-header'><h2 class='year-title'>" . $firstYear . "</header></h2>";
    						}
    					?>
    					<div id="show-<?php the_ID(); ?>" class="show-content">
    						<div class="showLeft">
    							<!-- Output the date of the occurrence-->
    							<?php echo eo_get_the_start('M jS'); ?> - <?php echo eo_get_the_end('M jS'); ?>
    						</div>
    						<div class="showRight">
    							<?php
    								//build out the link tag if a link is added to the show
    								$linkVar = get_post_meta($post->ID, 'Link', true);
    								if ($linkVar){
    									echo '<a href="' . $linkVar . '">';
    								}
    							?>
    							<?php the_title(); ?>
    							<?php
    								//build out the closer if a link is added to the show
    								if ($linkVar){
    									echo '</a>';
    								}
    							?>
    						</div>
    					</div>
    				<?php endwhile; ?><!----The Loop ends-->
    			</article>

    Thanks for posting – looks pretty good! If I may, I might use this on the plug-in website as an example of how templates can be customised / example of template functions.

    It’ll be good to see the finished product too – I’m intersted in seeing how the plug-in is used. (If it’s ok, I might link to the website from the plug-in website?).

    Thread Starter stinoga

    (@stinoga)

    Sure! Both of those are cool with me Stephen. Anything I can do to help! The site should be live in a couple weeks, I can give you the link then.

    Thread Starter stinoga

    (@stinoga)

    Site should be live in a few days Stephen. The only other callout I have is that it would be nice if the event limit on the archive page didn’t reflect that of the blog. I had to set mine to 50 so everything would show, but this creates one hefty blog page.

    Sorry to nitpick, just want to help. Thanks a ton for this awesome plugin!

    I might introduce that as an option in the settings in the future – but it’s possible to edit the posts per page by using some of WordPress’ filters:

    add_action('pre_get_posts','my_change_event_posts_per_page');
    function my_change_event_posts_per_page( $query ) {
    	if( $query->is_main_query() && !is_admin() &&(is_post_type_archive( 'event' ) || eo_is_venue() || is_tax('event-category')|| is_tax('event-tag'))) {
    		$query->set( 'posts_per_page', '5' );
    	}
    }

    eo_is_venue is the only plug-in specific function which checks if a venue is being displayed.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Event Organiser] Getting an events event-category’ is closed to new replies.