Home › Forums › Calendar Products › Events Calendar PRO › How to display the child category of a specific parent category…
- This topic has 4 replies, 2 voices, and was last updated 9 years, 1 month ago by Brook.
-
AuthorPosts
-
January 13, 2015 at 6:51 am #931984GabrielParticipant
Hi,
i want to show child category of a specific parent category. In the normal Template (single.php) that works:
<?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(7, $childcat)) { echo $childcat->cat_name; }} ?>
How does ist work in singel-event.php?
I try this, but it dont work.
<?php foreach((tribe_get_event_categories()) as $childcat) { if (cat_is_ancestor_of(7, $childcat)) { echo $childcat->cat_name; }} ?>
Thanks for your help!
January 13, 2015 at 8:33 pm #932429BrookParticipantHowdy Gabriel,
Good question. You actually can use the builtin WP function to do it in both cases: get_categories(). As you can see you can pass it the parent category ID via ‘child_of ‘, so it will only retrieve the children of that category. No need to bother with an if inside of a foreach. So just run get_categories() and set child_of to the parent ID. If you want to do this for Events categories then you can set the taxonomy to ‘tribe_events’. And there you have it, the complete list!
Does that make sense? Did that work? Please let me know.
Cheers!
– Brook
January 14, 2015 at 7:46 am #932641GabrielParticipantIf you want to do this for Events categories then you can set the taxonomy to ‘tribe_events’.
What do you exactly mean with it? I try this, but it dont work 🙁
<?php $args = array( 'taxonomy' => 'tribe_events' ); $categories = get_categories($args); foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(7, $childcat)) { echo $childcat->cat_name; }} ?>
I am sorry, I think my WordPress Codex know-how is not enough here.
January 16, 2015 at 8:18 pm #933928BrookParticipantHowdy Gabriel,
What do you exactly mean with it? I try this, but it dont work
You got it right, you set the taxonomy. But, then you didn’t call that variable in the rest of your code. Nor did you set child_of. For what it’s worth, when you are writing in a programming language usually you need to either be a programmer of hire one. The support we offer here is meant to be a general overview as outlined in our scope of support. We do not provide specific code to your site. It is up to you to turn the overview into working code.
That said sometimes I can sneak a little site specific code past my manager. I have not tested this and it might take a little tweaking, but this is a really good start:
[php]
$categories = get_categories(array(
‘taxonomy’ => ‘tribe_events’,
‘child_of’ => 7,
));
foreach($categories as $childcat) {
echo $childcat->cat_name;
}
[/php]I also just realized that my link above doesn’t work. This might help you to further your knowledge of that function: http://codex.wordpress.org/Function_Reference/get_categories
Hopefully that helps. Cheers!
– Brook
March 20, 2015 at 11:11 pm #949831BrookParticipantSince this topic has gone for a spell without an update it is getting archived. If you need anything else though please feel free to open a new topic, we would love to help. Cheers!
– Brook
-
AuthorPosts
- The topic ‘How to display the child category of a specific parent category…’ is closed to new replies.