I’m trying to write a kind of “breadcrumb” function in my “functions.php”
I’d like to query if I’m on a term-page and if so I want to print the current term I’m in.
By “term-page” I mean the following. I list all terms of a custom-taxonomy (associated with a custom-post-type) as kind of categories in my header. I do this with get_term_link($term->slug, 'my_taxonomy')
;
In my new function for the breadcrumbs I’d like to query if I’m on one of this pages and print this term.
First off, â¦Â I’m doing this â¦
if ( is_taxonomy_hierarchical('my_taxonomy) ) {
echo "test";
But now my function is depending on this my_taxonomy
string. I’d love to work this function for all upcoming taxonomies. How can I do this? There are conditional tags like is_category()
that doesn’t need any params. Why do all term- or taxonomy-conditionals need this param?
And how can I print the current-term i’m in. Right now I’m just echoing “test” up there, however I’d like to print the current term.
Any ideas on that? Thank you in advance.
UPDATE:
function list_breadcrumbs() {
$q_object = get_queried_object();
$taxonomy = $q_object->taxonomy;
$seperator = " <span class='separator'>⟩</span> ";
if ( !is_home() ) {
echo "<a href='" . get_bloginfo('url') . "' title='Home'>Home</a>" . $seperator;
if ( is_category() ) {
$category = get_the_category();
echo "<span class='breadcrumb'>" . $category[0]->cat_name . "</span>";
} else if ( is_tax( $taxonomy ) ) {
echo "The Term Name";
} else if ( is_single() ) {
â¦
} else if ( is_page() ) {
â¦
You’ll want
get_queried_object()
. This is a very generic function – and simply returns the queried object- so a single post, this would be a post object.For instance, the return object may be of the form:
So for instance:
To use this in a function:
Then just
wpse51753_breadcrumbs();
in your template wherever you want to display the breadcrumbs.