Skip Navigation

[Resolved] I need to have parent category at breadcrumbs navigation in archives

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 13 replies, has 2 voices.

Last updated by toolset-dave 7 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#572292

Hi, I have created archive page which works well. I set it up to show the current name of the category [wpv-taxonomy-archive info= "name" ], but I don´t know how to show it´s parent category.

#572325

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

This can be achieved by using the info='parent' attribute.

Thanks,
Shane

#572498

Hi Shane,

[wpv-taxonomy-archive info='parent'] does not work for me. It just shows a number... instead of parent category. For information Taxonomy type is set as Hierarchical.

#572619

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

It seems that the parameter returns the id of the parent. Since we have the id we can use some custom code to get the parent title.

Add the following to your functions.php file

// Add Shortcode
function term_parent( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'parent_id' => '',
			'taxonomy' => '',
		),
		$atts
	);

	$term = get_term( $atts['parent_id'], $atts['taxonomy'] );
	return $term->name;

}
add_shortcode( 'term_parent', 'term_parent' );

Then you can use this shortcode by doing this.

[term_parent parent_id="[wpv-taxonomy-archive info='parent']" taxonomy="taxonomy_slug"]

Now replace the word 'taxonomy_slug' with the slug of your taxonomy and it should give you the title of your parent term.

Please let me know if this helps.
Thanks,
Shane

#572671

Brilliant, works great!

But one thing to have it 100% - I need to get a URL of this parent category. I tried to modify your shortcode, but without success.

#572742

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

Try this one instead.

// Add Shortcode
function term_parent( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'parent_id' => '',
            'taxonomy' => '',
        ),
        $atts
    );
 
    $term = get_term( $atts['parent_id'], $atts['taxonomy'] );
    $term_url =  get_term_url($term);
    return '<a href="' . esc_url( $term_url) . '">' . $term->name . '</a>';
 
}
add_shortcode( 'term_parent', 'term_parent' );

Try this and let me know if it helps.

Thanks,
Shane

#572764

Hi Shane,

I tried this code instead of previous, but there must be some error, because if I place the code into functions.php the page would not load.

#573304

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

I see the issue 🙂

Use this function as i've fixed it.

// Add Shortcode
function term_parent( $atts ) {
  
    // Attributes
    $atts = shortcode_atts(
        array(
            'parent_id' => '',
            'taxonomy' => '',
        ),
        $atts
    );
  
    $term = get_term( $atts['parent_id'], $atts['taxonomy'] );
    $term_url =  get_term_link($term);
    return '<a href="' . esc_url( $term_url) . '">' . $term->name . '</a>';
  
}
add_shortcode( 'term_parent', 'term_parent' );

Thanks,
Shane

#573812

Hi Shane,

thanks, we are getting close to solution, it works now in child archive pages. But if I want to see parent page, there is the same problem as before, the page would not load. Any idea?

#573834

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

Would you mind providing me with admin access to the website so that I can have a look as it should work.

The private fields have been enabled for your next response.

Thanks,
Shane

#573879

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

I'm not sure where you placed the code I gave but if you remove it does the archive show up ?

Please let me know.
Thanks,
Shane

#573910

Hi Shane,

you can find shortcode in layout link I send you in private message in Loop Output Editor - [term_parent parent_id="[wpv-taxonomy-archive info='parent']" taxonomy="kategorie"]

And the shortcode code is in functions.php, toolset-starter theme, not the child one.

Yes, if I remove it, the parent category will show up.

#573915

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dave,

I'm making a final adjustment to the code.

// Add Shortcode
function term_parent( $atts ) {
   
    // Attributes
    $atts = shortcode_atts(
        array(
            'parent_id' => '',
            'taxonomy' => '',
        ),
        $atts
    );
if ($atts['parent_id'] != 0){
   
    $term = get_term( $atts['parent_id'], $atts['taxonomy'] );
    $term_url =  get_term_link($term);
    return '<a href="' . esc_url( $term_url) . '">' . $term->name . '</a>';
   }
}
add_shortcode( 'term_parent', 'term_parent' );   

I've changed it to account for if the archive doesn't have a parent. I've already tested the code on your site so its working now 🙂

Thanks,
Shane

#574012

Great work, Shane. Thank you.