Category above post varies

Hi there,

last night I published a new post on my blog (www.verenawandert.de) and there was a difference to the older posts. For almost all posts I use the main category “Reisebericht” and then the sub category for the continent (Afrika, Asien, Europa, etc - this one differs depending on what the post is about), and then another sub category for the exact country (Kroatien, China, etc).
With the Activello design, there always is a category displayed above the post and for all my older posts it if the first category (the continent one). But with my most recent one, it is showing the second sub category (the country one). And now it’s a little mixed up.

I think I should mention that all of the old posts have not been published on this blog, but imported from my old blog. The most recent one (where the country is displayed instead of the continent) however was published on the new blog.

I’d like the category to be of the same kind every time, and it’d be best if it was the first category (the continent and not the country).

Thanks in advance for your help!

Hi,
could you give us links to see what difference you are talking about ?

Jech

Hi,

thanks for your reply!

The link to my blog is www.verenawandert.de and my problem can be seen on the home page - the category is always being mentioned above the small purple line (above the post title), so at the moment it’s “Deutschland” for the first post, “Diverses” for the second post, and then there’s “Afrika” and “Naher Osten”, etc. So “Diverses”, “Afrika”, and “Naher Osten” are all the first sub category, whereas “Deutschland” is the second sub category!

Thanks

Hi @lavendel,

I hope you are well today and thank you for your question.

The theme displays first top category attached to the post as shown in the attached screenshot so you can try reordering the categories using the below plugin.

Best Regards,
Movin

Dear Movin,

thanks for your reply.

I have installed the recommended plugin, however, the problem hasn’t changed. I attached a photo of the way the taxonomy is being displayed by the plugin.

I also attached a screenshot of my blog where it’s working right (the one where it says “Afrika” (Africa) and “Naher Osten” (Middle East) on top of the post) and the one where it’s working wrong (where it says “Deutschland” (Germany) on top of the post). As you can see from the taxonomy order screenshot, Afrika and Naher Osten are on the same level as Europa; however, Europa is not being displayed, but Deutschland (which is a sub category to Europa).

Unfortunately I can’t find an attachment to your reply, except for the link to the plugin :frowning:

I hope all of this makes sense and you understand my problem.

Thanks!

Hi @lavendel,

Let’s achieve this simple way using custom solution.

Just add the following functions in the activello theme functions.php file replacing the existing function activello_get_single_category in that file which you will find on line number 235


function get_depth($id = '', $depth = '', $i = 0)
{
	global $wpdb;

	if($depth == '')
	{
			$depth = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '".$id."'");
			return get_depth($id, $depth, $i);
		
	}
	elseif($depth == '0')
	{
		return $i;
	}
	else
	{
		$depth = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '".$depth."'");
		$i++;
		return get_depth($id, $depth, $i);
	}
}

/* Get Single Post Category */
function activello_get_single_category($post_id){

    if( !$post_id )
        return '';

    $post_categories = wp_get_post_categories( $post_id );   
    

    if( !empty( $post_categories ) ){
        
        foreach ($post_categories as $post_cat) {
           $cat = get_depth($post_cat);
           if($cat <= 1){
               return wp_list_categories('echo=0&title_li=&show_count=0&include='.$post_cat);
           }
        }

        return wp_list_categories('echo=0&title_li=&show_count=0&include='.$post_categories[0]);

    }
    
    
    return '';
}

Best Regards,
Movin

Beautiful! This works perfectly, thank you so much! :slight_smile:

You are most welcome here :slight_smile:

Hi Movin,

I tried your code above that you recommended for displaying a single category but it doesn’t seem to work from my end. Do you happen to have the original code that is innate with the activello theme? I need it to restore my site without having to reset it all…

i’m looking for this section : /* Get Single Post Category */

thank you

@jonathantao To help us keep support thread separates could you please create your own thread for your question here https://colorlibsupport.com/c/activello/ instead of replying on others thread as it makes the thread messy and hard to read.

If you want to you can also add reference of this thread in your newly created thread.

We would be more than happy to help you on your new thread.

Will do @Movin. Thankfully I was able to resolve this issue.

@jonathantao You are always welcome :slight_smile: