0

I've set up different post types with custom taxonomies and to code out a breadcrumb I need to have access to the terms of the post, the user is actually reading.

Note that my terms are hierarchical (like the categories) and that I need to display them in the hierarchical order in the breadcrumb.

I use the terms to categorize my posts. A user can navigate (navbar) to a site that display all the top level terms. He can then choose what he wants to read. If necessary (that differs from a top level term to another) he then is forwarded to another page that displays the child terms of the therm just chosen. After taking another choice he then sees the archive page that displays all the posts of that sub-term.

Now in the single.php of that exact post I want a breadcrumb that displays the path the user went trough.

Home / My Posts / Parent / Child / Post1

The child is in italics because that's an optional term. For some posts there is only a top-level term.

Now to achieve this, I need a method to get these one or two therms when viewing the single.php.

How can I do this?

1 Answer 1

0

Solved

I've solved it by myself.

The WordPress function get_the_term_list() returns the terms of the post, but unfortunately they are in the reversed hierarchical order, so I had to turn them around.

$id = get_the_ID(); 
$terms = get_the_term_list( $id , $taxonomy , '' , $randomstring );

$terms_array = explode( $randomstring , $terms );
$terms_string = implode( $separator , (array_reverse($terms_array)));

$terms_string can nou easily be integrated into the breadcrumb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.