Tagged: yigit
-
AuthorPosts
-
September 15, 2015 at 1:58 pm #503342
Dear Enfold-Team,
I’d like to show only the posts parent-category-name in the meta-section of the postslider. I already found a solution to show the complete list of categories attached to the specific post. But I want to show just the parent-category-name.
Can you help me?
Thx in advance,
ehnatnorSeptember 15, 2015 at 7:53 pm #503639Hey ehnatnor!
where can we see the parent category names in question? can you highlight using screenshots please? you can use imgur or dropbox.
Regards,
AndySeptember 15, 2015 at 8:17 pm #503660Hi Andy,
there are only five parent categories: “Pfarrei”, “St. Anna”, “St. Ludgerus”, “St, Pantaleon”, “St. Stephanus”. These five categories are all on the same (top)-level. All of these five categories already have/will have children one level beneath.
I want to display only these five top-level-/parent-categories in the meta-section of each post in the postslider.php. The child-categories (i.e. “Fusion”, attached to the parent-category “Pfarrei”) should not appear in the meta-section.The code I’m actually using to display the names of the attached categories (parent- and child-categories) in the meta-section of each post is:
$taxonomies = get_object_taxonomies(get_post_type($the_id)); $cats = ''; $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', array('post_tag','post_format'), get_post_type($the_id), $the_id); if(!empty($taxonomies)) { foreach($taxonomies as $taxonomy) { if(!in_array($taxonomy, $excluded_taxonomies)) { $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' '; } } } if(!empty($cats)) { $output .= '<div class="slide-meta-cats">'; $output .= $cats; $output .= '</div><div class="slide-meta-del">|</div>'; }
I hope that these informations make my intention more clear.
Thx,
ehnatnorSeptember 16, 2015 at 1:57 pm #504089Hi!
Please try changing your code to following one
$taxonomies = get_object_taxonomies(get_post_type($the_id)); $cats = ''; $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', array('post_tag','post_format'), get_post_type($the_id), $the_id); if(!empty($taxonomies)) { foreach($taxonomies as $taxonomy) { if(!in_array($taxonomy, $excluded_taxonomies)) { $cats .= get_cat_name(); } } } if(!empty($cats)) { $output .= '<div class="slide-meta-cats">'; $output .= $cats; $output .= '</div><div class="slide-meta-del">|</div>'; }
Best regards,
YigitSeptember 16, 2015 at 3:16 pm #504177Hi Yigit,
thanks for your reply!
But your changes to the code don’t work. The difference between the listed code in my post above and yours is just the function “get_cat_name” vs. “get_the_term_list”. With my code all categories of a post are listed in the meta-section. With the “get_cat_name” function it’s only possible to show a specific category by its ID. Actually no category is listed if I use your code.I’m still searching for a solution that allows me to show just the top-level-category of a post in the meta-section of the postslider.php.
It would be great if someone could help me.Thanks in advance,
ehnatnorSeptember 22, 2015 at 2:17 pm #507044September 22, 2015 at 3:41 pm #507137Hi Yigit,
since my last post I still haven’t found what I was looking for. With your code nothing changed as I wrote in my last post. Do you have any other proposals how to reach my goal.
Regards,
ehnatnorSeptember 25, 2015 at 9:35 am #508844Hi!
You can use this function: https://codex.wordpress.org/Template_Tags/wp_list_categories#Display_Categories_Assigned_to_a_Post
Set the “depth” parameter to 1 to display only top level categories. The example on the link should work in your case.
Cheers!
IsmaelOctober 6, 2015 at 11:59 am #514317Hi Ismael,
I’ve pasted the example in my postslider.php but nothing happened. Now no category is listed in the post-meta-section.
I changed it back to my old version but I’m a little bit helpless …ehnatnor
October 7, 2015 at 9:57 am #515057Hi!
I think it would be best to hire a freelancer for this job, because we can only provide basic support in this forum and it seems that it needs a lot of time to find a solution for this. You can find good people for example here: http://kriesi.at/contact/customization
Cheers!
Andy -
AuthorPosts
- You must be logged in to reply to this topic.