Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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,
    ehnatnor

    #503639

    Hey ehnatnor!

    where can we see the parent category names in question? can you highlight using screenshots please? you can use imgur or dropbox.

    Regards,
    Andy

    #503660

    Hi 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,
    ehnatnor

    #504089

    Hi!

    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,
    Yigit

    #504177

    Hi 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,
    ehnatnor

    #507044

    Hey!

    Sorry for the late reply!
    Have you been able to figure it out?

    Cheers!
    Yigit

    #507137

    Hi 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,
    ehnatnor

    #508844

    Hi!

    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!
    Ismael

    #514317

    Hi 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

    #515057

    Hi!

    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

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.