Support

Home Forums Event Espresso Premium Dynamically linking category labels to category pages

Dynamically linking category labels to category pages

Posted: August 9, 2012 at 7:32 am

Viewing 7 reply threads


Runemester

August 9, 2012 at 7:32 am

I realize this may go beyond a \’regular\’ support question but I\’m no php-wiz and I hope someone might have an idea that can help me along.
Here is the scenario: In the event_list_display template I\’d like to list the categories every single event belongs to. I\’ve managed to do this using the shortcode echo do_shortcode(\'[CATEGORY_NAME event_id=\"\'.$event_id.\'\"]\')

I would however like to be able to customize the output somewhat more. First of all I’d like to be able to style the categories\’ labels seperately eg. in a unordered list. The reason for this being that I\’d like to assign different colors to different categories and link each category lable to a category page displaying a list of events belonging to the category label clicked. But no luck here.

And this connected to another issue…

So far I’ve gone about this by setting up a page for each category displaying the list of events belonging to that particular category. Every category page is a child page of the page containing the entire event list.

I’ve given every page the exact same name as the category_identifier. The idea being that I could solve my problem by dynamically outputting the category_identifier and append it to the base url of the parent page and output the link on the top-level event-list page.

So far far I’ve managed by using the above mentioned shortcode and wrapped the output in a link (as above – with the exception that the shortcode outputs the category_name – not the identifier). This works as long as only one category is assigned to the event. And its not exactly pretty.

This is about as far as I’ve come… I been over the documentation but so far I’ve hit a wall. Any ideas will be greatly appreciated!

Thanks
Rune


Josh

  • Support Staff

August 10, 2012 at 7:34 am

Hey Runemaster,

There was a new shortcode added to 3.1.26.P that might be just what you’re looking for. It was actually something that another user of Event Espresso contributed in the forums.

The syntax goes something like this:
[EVENT_ESPRESSO_CATEGORIES cats=”1,2,3,4″ links=”76,79,86,88″]
cats = the category id you want to show
links = the page ID that this category is shown on


Runemester

August 13, 2012 at 3:16 am

Hi Josh,

Great news! I’ll keep a look out for the shortcode in the upcoming release. Thanks!


Josh

  • Support Staff

August 13, 2012 at 9:23 am

Event Espresso 3.1.26 has been released, and the above shortcode is included.


Runemester

August 13, 2012 at 11:08 am

Thanks! Still having problems though…
Heres the event list display. What I want to do is have each event in the list labelled with its category – and then link the category-label to the category event list display.
I’m trying to figure out how to make this happen dynamically – being able to print the category_identifier would work as I’ve named all category pages accordingly. I’ve almost made it work using the shortcode [CATEGORY_NAME event_id=”‘.$event_id.'”]. But as you can se I have problems making this work with special characters ‘æøå’ (its in Danish) eg. with the category ‘Særrangementer’ (special events). Another problem is formatting the links when an event belongs to two or more categories. For the time being it just prints the category names in one ‘block’.


Josh

  • Support Staff

August 15, 2012 at 9:11 am

It looks like you’ve got the special characters part worked out, as ‘Særrangementer’ looks correct to me. I could be wrong about that though.

So if you want to add markup so that the each of the category names will be within a list item, you’ll need to modify the espresso_event_category_data function in /includes/functions/main.php which starts around line 736.

If you look at that function, the line where you’ll want to add the markup is the one that has the category name. Something like this will wrap it in an list item and add a class name based on the unique category ID for styling:

$category_data['category_name'] .= '<li class="' . $result->category_identifier . '">' . $result->category_name . '</li>';

Note that this is a pluggable function, so the entire function can be copied over to the custom_functions.php file that is included with the custom files add-on. If you copy this function over, your changes will not get overwritten when Event Espresso gets updated.

By the way, this site looks awesome, please consider submitting this site for inclusion to our showcase.


Runemester

August 16, 2012 at 5:45 am

Hi Josh,

Thanks a lot for your helpful suggestions. I finally nailed it by modifying the file you suggested (line 755) to this:

$category_data['category_name'] .= 'category_identifier . '"&gt;'.'<a>category_identifier . '" title="Se alle arrangementer i kategorien: ' . $result-&gt;category_name . '"&gt;' . $result-&gt;category_name . '</a>'.'';    

as you can see I modified it quite a bit – to make it behave as I intended. Linking category names by way of the category identifier to category pages (all are subpages of the page containing the event list). I’ll be sure to upgrade my license to be able to add the custom files add-on.

By the way: A small localisation issue on line 536 – the ‘Unlimited’ text should probably be added to the textdomain.

And thanks for complimenting the site. I’ll submit my site to the showcase once it’s ready to go live 😉 Cheers Rune

note: it seems the code is being stripped of some of the tags – sorry…

  • This reply was modified 12 years, 4 months ago by Runemester.


Josh

  • Support Staff

August 16, 2012 at 8:51 am

Glad you’ve found a solution that works.

We have an open ticket to go through and address the non-localized text strings, and ‘Unlimited’ is on that to-do list.

Viewing 7 reply threads

The support post ‘Dynamically linking category labels to category pages’ 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