Support

Home Forums Event Espresso Premium List of events separeted by categories

List of events separeted by categories

Posted: May 16, 2014 at 12:03 am

Viewing 3 reply threads


Michael Friedmann

May 16, 2014 at 12:03 am

Hello forum,

it try to figure out, wich code i need to sho the categories for my list.

I used the custom template addon to create my list. I throw the select, because i want it as a list one after another. Category, below all events belonging to, and so on. So far so good.
It works with the event but not with the category of each event.
I can show the id of the category but not the title. Here’s my code, maybe one of you can help me with this.
`<?php
//Template: Event Listings Table
//Description: This template creates a list of events, displayed in a table. It can dipsplay events by category and/or maximum number of days.
//Shortcode Example: [EVENT_CUSTOM_VIEW template_name=”events-table”]
//Requirements: CSS skills to customize styles, some renaming of the table columns

//The end of the action name (example: “action_hook_espresso_custom_template_”) should match the name of the template. In this example, the last part the action name is “default”,
add_action(‘action_hook_espresso_custom_template_events-table’,’espresso_custom_template_events_table’);

function espresso_custom_template_events_table(){

global $this_event_id, $events, $wpdb;

//Get the categories
$sql = “SELECT * FROM ” . EVENTS_CATEGORY_TABLE;
$temp_cats = $wpdb->get_results($sql);

?>

<table id=”ee_filter_table” class=”espresso-table” width=”100%”>
<thead class=”espresso-table-header-row”>
<tr>
<th class=”th-group”><?php _e(‘Event’,’event_espresso’); ?></th>
<th class=”th-group”><?php _e(‘Venue’,’event_espresso’); ?></th>
<th class=”th-group”><?php _e(‘Date’,’event_espresso’); ?></th>
<th class=”th-group”></th>
</tr>
</thead>
<tbody>
<?php

foreach ($events as $event){
$button_text = __(‘Register’, ‘event_espresso’);
$alt_button_text = __(‘View Details’, ‘event_espresso’);//For alternate registration pages
$externalURL = $event->externalURL;
$button_text = !empty($externalURL) ? $alt_button_text : $button_text;
$registration_url = !empty($externalURL) ? $externalURL : espresso_reg_url($event->id);
if ( ! has_filter( ‘filter_hook_espresso_get_num_available_spaces’ ) ){
$open_spots = apply_filters(‘filter_hook_espresso_get_num_available_spaces’, $event->id); //Available in 3.1.37
}else{
$open_spots = get_number_of_attendees_reg_limit($event->id, ‘number_available_spaces’);
}
$live_button = ‘id.'” href=”‘.$registration_url.'”>’.$button_text.’‘;
$event_status = event_espresso_get_status($event->id);

//Check for Multi Event Registration
$multi_reg = false;
if (function_exists(‘event_espresso_multi_reg_init’)) {
$multi_reg = true;
}
$cart_link = ”;

//Create an add to cart link
if ($multi_reg && $event_status == ‘ACTIVE’ && empty($externalURL)) {
$params = array(
//REQUIRED, the id of the event that needs to be added to the cart
‘event_id’ => $event->id,
//REQUIRED, Anchor of the link, can use text or image
‘anchor’ => __(“Add to Cart”, ‘event_espresso’), //’anchor’ => ”,
//REQUIRED, if not available at this point, use the next line before this array declaration
// $event_name = get_event_field(‘event_name’, EVENTS_DETAIL_TABLE, ‘ WHERE id = ‘ . $event_id);
‘event_name’ => $event->event_name,
//OPTIONAL, will place this term before the link
‘separator’ => ‘ ‘.__(“or”, ‘event_espresso’).’ ‘
);

$cart_link = event_espresso_cart_link($params);
}

if($open_spots < 1 && $event->allow_overflow == ‘N’) {
$live_button = __(‘Sold Out’, ‘event_espresso’);
$cart_link = ”;
} else if ($open_spots < 1 && $event->allow_overflow == ‘Y’){
$live_button = !empty($event->overflow_event_id) ? ‘overflow_event_id).'”>’.__(‘Join Waiting List’, ‘event_espresso’).’‘ : __(‘Sold Out’, ‘event_espresso’);
$cart_link = ”;
}

if ($event_status == ‘NOT_ACTIVE’) {
$live_button = __(‘Closed’, ‘event_espresso’);
$cart_link = ”;
}

?>

<tr class=”espresso-table-row cat-<?php echo $event->category_id; ?>”>

<td id=”event_title-<?php echo $event->id?>” class=”event_title”><?php echo do_shortcode(‘[CATEGORY_NAME event_id=”‘.$event_id.'”]’);?><br /><?php echo stripslashes_deep($event->event_name) ?></td>
<td id=”venue_title-<?php echo $event->id?>” class=”venue_title”><?php echo $event->venue_name ?></td>
<td id=”start_date-<?php echo $event->id?>” class=”start_date”><?php echo event_date_display($event->start_date/*.’ ‘.$event->start_time, get_option(‘date_format’).’ ‘.get_option(‘time_format’)*/) ?></td>
<td class=”td-group reg-col” nowrap=”nowrap”><?php echo $event_status == ‘ACTIVE’ ? $live_button . $cart_link : $live_button; ?></td>
</tr>
<?php } //close foreach ?>
</tbody>
</table>
<script type=”text/javascript”>

jQuery(document).ready(function(){

jQuery(“#ee_filter_cat”).change(function() {
var ee_filter_cat_id = jQuery(“option:selected”).attr(‘class’);
console.log(ee_filter_cat_id);
jQuery(“#ee_filter_table .espresso-table-row”).show();
jQuery(“#ee_filter_table .espresso-table-row”).each(function() {
if(!jQuery(this).hasClass(ee_filter_cat_id)) {
jQuery(this).hide();
}
});
if( ee_filter_cat_id == ‘ee_filter_show_all’) {
jQuery(“#ee_filter_table .espresso-table-row”).show();
}
});

});

</script>
<?php
}

Thanks for helping


Tony

  • Support Staff

May 16, 2014 at 4:02 am

As this is a customisation it is not something we can fully support, however looking at your code I can advise that this line:

<?php echo do_shortcode(‘[CATEGORY_NAME event_id="'.$event_id.'"]‘);?>

will currently not work as there is no $event_id variable.

Change that line to:

<?php echo do_shortcode('[CATEGORY_NAME event_id="'.$event->id.'"]');?>

Edit – Fixed the quotation marks in example shortcode.

  • This reply was modified 10 years, 6 months ago by Tony. Reason: Fixed quotation marks


Michael Friedmann

May 17, 2014 at 1:36 am

Thanks for your feedback.

But when i use this shortcode, everything shown up to this point is gone.
Now is no more events visible. Only the headline is standing there.

Maybe i cant integrate the $event_id variable in this site? Is it global?

Thanks for feedback.


Tony

  • Support Staff

May 19, 2014 at 5:15 am

Hi Michael,

Did you alter the code or copy the shortcode I provided and used that? Reason I ask is the forum editor has altered the quotation marks so the correct code would be:

<?php echo do_shortcode('[CATEGORY_NAME event_id="'.$event->id.'"]');?>

Does that then work?

$event_id is just a variable for holding the current Event ID, it is not global but as $event stores the ID (available through $event->id) it is not needed.


Michael Friedmann

May 19, 2014 at 6:50 am

Thank you for your response. Works perfect

Viewing 3 reply threads

The support post ‘List of events separeted by categories’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso