Oguzhan Altun
November 29, 2015 at 7:55 am
Hello,
We provide trainings in Geneva / Switzerland, where people speak either English or French. http://www.genevaphotoclub.com
So far we’ve been providing these trainings in English, but now we will start offering these courses in French as well (as separate events).
Is it possible to add a language tag to an event, so that users can easily see which training will be run in which language? I’m using the events table view template, so ideally I would like to have a separate column for language in this table .
Thanks
Tony
November 30, 2015 at 4:46 am
Add New Note to this Reply
Hi there,
Its possible to do this, but you will need a custom table view template to display the details on the language selected within the event.
You could use categories or tags for this within the event, then you’ll need to add some code to display a column to the event table and display the language based on the tag/category.
Oguzhan Altun
November 30, 2015 at 1:31 pm
Add New Note to this Reply
Hi Tony,
Which one do you think will be easier, if I create a separate category for french courses or if I use a tag for French? Hopefully tag can work, because I already use the categories for types of courses..
Josh
November 30, 2015 at 6:40 pm
Add New Note to this Reply
Tags are fine. There is a code example that shows how to use get_the_tags() to execute code in the WP codex if a specific tag is assigned to an event:
https://codex.wordpress.org/Function_Reference/get_the_tags#Execute_code_based_on_different_tag_values
Oguzhan Altun
December 2, 2015 at 7:16 am
Add New Note to this Reply
Hi Josh,
Thanks for your response. As you know, I don’t really know php at all, anyway you can help me integrate this into my custom table template? Here is the existing code right now. I added one training in french, with the tag français.
<?php
// Options
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$reg_button_text = !isset($reg_button_text) ? __('Register', 'event_espresso') : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
if ( have_posts() ) :
// allow other stuff
do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
?>
<?php if ($category_filter != 'false'){ ?>
<p class="category-filter">
<label><?php echo __('Category Filter', 'event_espresso'); ?></label>
<select class="" id="ee_filter_cat">
<option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
<?php
$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'name','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);
foreach($ee_terms as $term){
echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
}
?>
</select>
</p>
<?php } ?>
<?php if ($footable != 'false' && $table_search != 'false'){ ?>
<p>
<?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
</p>
<?php } ?>
<table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
<thead class="espresso-table-header-row">
<tr>
<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
<th class="th-group"><?php _e('Day','event_espresso'); ?></th>
<th class="th-group"><?php _e('Time','event_espresso'); ?></th>
<th class="th-group"><?php _e('Course','event_espresso'); ?></th>
<th class="th-group"><?php _e('Price','event_espresso'); ?></th>
<th class="th-group" data-sort-ignore="true"></th>
</tr>
</thead>
<?php if ($footable != 'false' && $table_paging != 'false'){ ?>
<tfoot>
<tr>
<td colspan="4">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;
//Debug
//d( $post );
//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
// loop thru terms and create links
$category_slugs = '';
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(' ', $category_slugs);
} else {
// event has no terms
$category_slugs = '';
}
}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
//Create the register now button
$live_button = '<a class="register-button" id="a_register_link-'.$post->ID.'" href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="soldout-button" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );
$startdate = date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );
$starttime = date_i18n( 'G:i', strtotime( $datetime->start_time('H:i:s') ) );
$endtime = date_i18n( 'G:i', strtotime( $datetime->end_time('H:i:s') ) );
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? sprintf("%0.2f",$ticket->ticket_price()) . '<span class="currency-code"> (CHF)</span>' : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$tickets_price_free_check = $ticket_price_data_value == 0 ? __('Free','event_espresso') : $ticket_price;
// OA Add so that it doesn't show free for full events
$tickets_price_free_check = (string)$ticket_price_data_value == '' ? __('Sold Out','event_espresso') : $tickets_price_free_check;
// grab primary datetime for event
$first_datetime = espresso_event_date_obj( $post->ID );
$tickets_left = $first_datetime instanceof EE_Datetime ? $first_datetime->tickets_remaining() : 0;
$tickets_left = $tickets_left === INF ? __('unlimited','event_espresso') : $tickets_left;
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo strtotime( $startdate ); ?>"><?php echo $startdate; ?></td>
<td class="day_of_week event-<?php echo $post->ID; ?>"><?php espresso_event_date_range( 'l', ' ', 'l', ' ', $event->ID() ); ?></td>
<td style="text-align:center" class="time event-<?php echo $post->ID; ?>"><?php echo $starttime ; ?> - <?php echo $endtime ; ?></td>
<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
<td style="text-align:center" class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $tickets_price_free_check; ?></td>
<td style="text-align:center" class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table>';
// allow moar other stuff
do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
else :
// If no content, include the "No posts found" template.
espresso_get_template_part( 'content', 'none' );
endif;
Tony
December 3, 2015 at 4:51 am
Add New Note to this Reply
Hi there,
We do not provide custom templates on the forums although we can help point you in the right direction.
You’ll need to add a column for languages to the headers and body of the table, then pull the tags for the post using:
$languages = get_the_tags();
if( $languages ) {
echo '<ul class="languages">';
foreach ($languages as $lang) {
echo '<li>' . $lang->name . '</li>';
}
echo '</ul>';
}
That will output a list of language tags assigned to the event.
Oguzhan Altun
December 3, 2015 at 6:00 am
Add New Note to this Reply
Hello,
So I tried, but have some issues. Here is how it looks:
http://www.genevaphotoclub.com/test/
What I did:
Added this to the heading:
<th class="th-group"><?php _e('Language','event_espresso'); ?></th>
Added your code in the body.
Then created the following code trying to imitate from the other lines into the table:
<td style="text-align:center" class="languages-<?php echo $post->ID; ?>"><?php echo $languages; ?>; ?></td>
Can you help me what i did wrong?
Oguzhan Altun
December 3, 2015 at 6:01 am
Add New Note to this Reply
overall code looks like this:
<?php
// Options
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$reg_button_text = !isset($reg_button_text) ? __('Register', 'event_espresso') : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
if ( have_posts() ) :
// allow other stuff
do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
?>
<?php if ($category_filter != 'false'){ ?>
<p class="category-filter">
<label><?php echo __('Category Filter', 'event_espresso'); ?></label>
<select class="" id="ee_filter_cat">
<option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
<?php
$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'name','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);
foreach($ee_terms as $term){
echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
}
?>
</select>
</p>
<?php } ?>
<?php if ($footable != 'false' && $table_search != 'false'){ ?>
<p>
<?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
</p>
<?php } ?>
<table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
<thead class="espresso-table-header-row">
<tr>
<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
<th class="th-group"><?php _e('Day','event_espresso'); ?></th>
<th class="th-group"><?php _e('Time','event_espresso'); ?></th>
<th class="th-group"><?php _e('Course','event_espresso'); ?></th>
<th class="th-group"><?php _e('Language','event_espresso'); ?></th>
<th class="th-group"><?php _e('Price','event_espresso'); ?></th>
<th class="th-group" data-sort-ignore="true"></th>
</tr>
</thead>
<?php if ($footable != 'false' && $table_paging != 'false'){ ?>
<tfoot>
<tr>
<td colspan="4">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;
//Debug
//d( $post );
//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
// loop thru terms and create links
$category_slugs = '';
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(' ', $category_slugs);
} else {
// event has no terms
$category_slugs = '';
}
}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
//OA Add: Language
$languages = get_the_tags();
if( $languages ) {
echo '<ul class="languages">';
foreach ($languages as $lang) {
echo '<li>' . $lang->name . '</li>';
}
echo '</ul>';
}
//Create the register now button
$live_button = '<a class="register-button" id="a_register_link-'.$post->ID.'" href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="soldout-button" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );
$startdate = date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );
$starttime = date_i18n( 'G:i', strtotime( $datetime->start_time('H:i:s') ) );
$endtime = date_i18n( 'G:i', strtotime( $datetime->end_time('H:i:s') ) );
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? sprintf("%0.2f",$ticket->ticket_price()) . '<span class="currency-code"> (CHF)</span>' : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$tickets_price_free_check = $ticket_price_data_value == 0 ? __('Free','event_espresso') : $ticket_price;
// OA Add so that it doesn't show free for full events
$tickets_price_free_check = (string)$ticket_price_data_value == '' ? __('Sold Out','event_espresso') : $tickets_price_free_check;
// grab primary datetime for event
$first_datetime = espresso_event_date_obj( $post->ID );
$tickets_left = $first_datetime instanceof EE_Datetime ? $first_datetime->tickets_remaining() : 0;
$tickets_left = $tickets_left === INF ? __('unlimited','event_espresso') : $tickets_left;
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo strtotime( $startdate ); ?>"><?php echo $startdate; ?></td>
<td class="day_of_week event-<?php echo $post->ID; ?>"><?php espresso_event_date_range( 'l', ' ', 'l', ' ', $event->ID() ); ?></td>
<td style="text-align:center" class="time event-<?php echo $post->ID; ?>"><?php echo $starttime ; ?> - <?php echo $endtime ; ?></td>
<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
<td style="text-align:center" class="languages-<?php echo $post->ID; ?>"><?php echo $languages; ?>; ?></td>
<td style="text-align:center" class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $tickets_price_free_check; ?></td>
<td style="text-align:center" class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table>';
// allow moar other stuff
do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
else :
// If no content, include the "No posts found" template.
espresso_get_template_part( 'content', 'none' );
endif;
Tony
December 3, 2015 at 6:17 am
Add New Note to this Reply
$languages is now an array of tag objects assigned to the event (if any), you need to loop through $languages as shown above to show a list of tags assigned to the event.
Oguzhan Altun
December 3, 2015 at 6:20 am
Add New Note to this Reply
Sorry how do i do that?
Whatever i did seems to correctly output the language tags for each event, but they show above the table rather than inside the table…
http://www.genevaphotoclub.com/test/
Tony
December 3, 2015 at 7:36 am
Add New Note to this Reply
You need to move:
if( $languages ) {
echo '<ul class="languages">';
foreach ($languages as $lang) {
echo '<li>' . $lang->name . '</li>';
}
echo '</ul>';
}
Down inplace of where you have:
echo $languages
Like this – http://pastebin.com/tx9CBFzF
Oguzhan Altun
December 3, 2015 at 10:20 am
Add New Note to this Reply
great, this worked perfectly. Thank you!