have you tried template file templates/placeholders/categories.php – http://wp-events-plugin.com/documentation/using-template-files/
??
Here’s what I want to do. Create a placeholder called #_CATEGORYPARENTLINK
I can do that. Now I need to know the syntax to display category depth=1 (parent) for an event.
It would work exactly the same as #_CATEGORYLINK but it would exclude child categories.
you can try this snippet or modify – http://pastebin.com/uLEak8Q5
(paste in your theme functions.php)
Hm… that’s a start — it creates the placeholder #_CATEGORYPARENTLINK, but that’s about it. Let me see if I can rephrase what I am looking for…
For each event, get its parent category
okay, if you are successful on rephrasing you might want to share it to the community.
I am stuck on this one. I don’t see where the code decides which category to show, of all the categories and subcategories an event might belong to. Show me how to echo an event’s categories and subcategories and maybe I can make some headway….
the snippet should get the parent category of the event? also, you can use print_r($EM_Category);
or see this link http://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/
No, the snippet does not produce anything. $replace remains at ” after line 7. I’ve read the placeholder tutorial a million times, I got that part.
you can just use get_terms as well – http://codex.wordpress.org/Function_Reference/wp_get_object_terms
Since all you need is $EM_Event->post_id. Then the parent should be in that returned object.
ok… I got something working. Your snippet returns a parent of a child, but returns nothing if it is not a child (i.e. a parent). So I changed line 7 to
$replace = '<a href="' . get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY ) . '">' . $EM_Category->name . '</a>';
That seems to work. But is the snippet the most efficient way to do this? I was trying to do something like:
if ( $this->parent == 0 ) $replace = $this->name;
else $replace = $this->parent [but turn id into name]
But I can’t figure out the syntax. Either way, thanks!
I changed your line 12 to
if ( ( count( $child ) >= 0 ) && ( $EM_Category->name == $arrterm->name ) ) {
and got rid of the redundant else if. Works great. Thanks so much!
…and so it doesn’t choke if an event has no parent category associated with it, wrap with a conditional:
$replace = '';
if ( $EM_Category->name ) {
etc...
}
break;
Also modified your lines 13 and 20.
Before:
get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY )
get_term_link( $arrterm->name, EM_TAXONOMY_CATEGORY )
After:
get_term_link( $EM_Category->slug, EM_TAXONOMY_CATEGORY )
get_term_link( $arrterm->slug, EM_TAXONOMY_CATEGORY )
I’d suggest you post your modified version to pastebin.com, to avoid any typos. thanks!