WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] #_CATEGORYLINK to diplay top level category of an event (16 posts)

  1. raskull
    Member
    Posted 1 year ago #

    I have event categories, and subcategories. Each event has its parent category, and a subcategory.

    When I use #_CATEGORYLINK I get, from among the event's categories and subcategories, the name with the highest alphabetical ranking.

    So an event categorized

    Fruit
     - Apples

    will display the category as Apples, not Fruit.

    Whereas an event categorized

    Apples
     - Macintosh

    will display the category as Apples.

    How can I return only the parent category?

    http://wordpress.org/extend/plugins/events-manager/

  2. agelonwl
    Member
    Posted 1 year ago #

    have you tried template file templates/placeholders/categories.php - http://wp-events-plugin.com/documentation/using-template-files/

  3. raskull
    Member
    Posted 1 year ago #

    ??

    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.

  4. agelonwl
    Member
    Posted 1 year ago #

    you can try this snippet or modify - http://pastebin.com/uLEak8Q5

    (paste in your theme functions.php)

  5. raskull
    Member
    Posted 1 year ago #

    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

  6. agelonwl
    Member
    Posted 1 year ago #

    okay, if you are successful on rephrasing you might want to share it to the community.

  7. raskull
    Member
    Posted 1 year ago #

    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....

  8. agelonwl
    Member
    Posted 1 year ago #

    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/

  9. raskull
    Member
    Posted 1 year ago #

    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.

  10. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    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.

  11. raskull
    Member
    Posted 1 year ago #

    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!

  12. agelonwl
    Member
    Posted 1 year ago #

    hi,

    edited the snippet at http://pastebin.com/uLEak8Q5

  13. raskull
    Member
    Posted 1 year ago #

    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!

  14. raskull
    Member
    Posted 1 year ago #

    ...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;
  15. raskull
    Member
    Posted 1 year ago #

    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 )
  16. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    I'd suggest you post your modified version to pastebin.com, to avoid any typos. thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.