Forum

Thread tagged as: Question, Events

Events categories links

Is there any way to create a dynamic list of "category links" for each of categories assigned to an event on it's detail page?

Only fields available from the event detail page are {category_slugs} and {category_names}... is there another way get this information?

Below works if a single category is selected, breaks when an event belongs to multiple categories (obviously)

<a href="category.php?cat=<perch:events id="category_slugs" />"><perch:events id="category_names" /></a>
Seth Girardin

Seth Girardin 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can also use perch_events_event_categories()

I guess that is something that I'm still not understanding how to do properly.

perch_events_event_categories() needs to be added to my event.php page, or is there a another way to retrieve that information directly into my event-detail.html template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can pass the result into the template using PerchSystem::set_var()

https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/

Something like this?

    $categories = perch_events_event_categories();


    PerchSystem::set_vars(array(
            'eventEnd'=> $eventEnd,
            'eventCategories'=> $categories
        ));

Not sure how to retrieve all assigned categories and their slugs and then reassemble in my template.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, just be sure to pass your arguments to perch_events_event_categories()

I apologize, not my strong suit.

Tried grabbing info from my event.html template, but when I do a showall, I only see the categories in the ID column and values of "true" assigned to them:

sports-recreation true town-services true

Category image

I'm looking for the event's separate categorySlug(s) & categoryTitle(s), where do they reside or what is the argument to pass to get them?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the event slug on the URL?

Yes.

/events/event.php?s=2016-01-08-senior-mixed-curling-championship

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so you'd use something like:

$categories = perch_events_event_categories(perch_get('s'), [
    'template' => 'event_category_link.html',
], true);

Still not working. Now the page loads blank. Path to template is correct and in place.

Did I add the code to the wrong place? Should it be down in the if (perch_get('s')) section?

<?php
    include('../perch/runtime.php');

        $opts_meta = array(
                'filter'=>'eventSlug',
                'match'=>'eq',
                'value'=>perch_get('s'),
                'template'=>'event.html',
                'skip-template'=>'true'
            );

       $data_meta = perch_events_custom($opts_meta);

           $title = $data_meta[0]['eventTitle'];

        $eventEnd = $data_meta[0]['eventDateTime'];
        $eventEnd = strtotime($eventEnd) + 3600;
        $eventEnd = date('Y-m-d H:i:s', $eventEnd);

      $categories = perch_events_event_categories(perch_get('s'), [
            'template' => 'event_category_link.html',
        ], true);

    PerchSystem::set_vars(array(
     'eventCategories'=> $categories,
            'eventEnd'=> $eventEnd
        ));

    perch_layout('events.above', array(
            'title'=> $title
        ));

    if (perch_get('s')) {
        perch_events_custom(array(
            'template'   => 'listing/event-detail.html',
            'filter'     => 'eventSlug',
            'match'      => 'eq',
            'value'      => perch_get('s'),
        ));
    }else{
        perch_events_custom(array(
            'template'   => 'listing/custom-listing-day.html',
            'sort'       => 'eventDateTime',
            'sort-order' => 'ASC',
            'filter'     => 'eventDateTime',
            'match'      => 'eqbetween',
            'value'      => date('Y-m-d, Y-m-31'),
        ));
    }
   perch_layout('events.below');
?>

Doesn't seem to be finding anything:

Array ( [perch_page_path] => /events/event.php [eventEnd] => 2016-01-08 09:00:00 [eventCategories] => )

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you getting your event back?

Yes, I'm getting it back.

Also not sure if this helps, I'm a set to development mode and haven't modified anything relating to Perch or the events app.

Perch: 2.8.20, PHP: 5.6.16, MySQL: 5.6.26, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (2.8.20), assets (2.8.20), categories (2.8.20), perch_events (1.9.2), perch_backup (1.2) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_events' ); PERCH_LOGINPATH: /perch PERCH_PATH: /home/norfolkct/public_html/perch PERCH_CORE: /home/norfolkct/public_html/perch/core PERCH_RESFILEPATH: /home/norfolkct/public_html/perch/resources Image manipulation: GD Imagick PHP limits: Max upload 16M, Max POST 32M, Memory: 256M, Total max file upload: 16M Resource folder writeable: Yes DOCUMENT_ROOT: /home/norfolkct/public_html HTTP_HOST: norfolkct.org REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Is there a way to test if the perch_events_event_categories function is actually working?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output for the page?

If I made the path for the template correct, the page doesn't load at all, no debug, nothing.

Below is returned, if template path purposely broken:

SELECT DISTINCT e.* FROM perch2_events e WHERE eventSlug='2016-01-08-gncc-senior-mixed-curling-championship' SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='12' SELECT * FROM perch2_events WHERE eventSlug = '2016-01-08-gncc-senior-mixed-curling-championship' SELECT categoryID FROM perch2_events_to_categories WHERE eventID = '12' SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='12' SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0

Template file not found: /home/norfolkct/public_html/perch/addons/apps/perch_events/templates/events//events/event_category_link.html

Could the perch_events_event_categories function be screwing up the template path? I fixed the path and double checked that the template "event_category_link.html" exists both in the templates/events/ and in the apps/perch_events/templates folders (as a test) still nothing.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure where you are now. What problem are you currently having?

The following doesn't work or debug (unless I purposely break the path to the template, then debug works, but the it doesn't do anything, see above)

$categories = perch_events_event_categories(perch_get('s'), [
    'template' => 'event_category_link.html',
], true);
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I'm probably out of suggestions then.

So there is no way to test if perch_events_event_categories is actually the issue? Why would the debug not work with correct path to linked template? Could this same function be done with straight PHP? (if so, how? :)