WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Breadcrumbs reversed with hierarchical taxonomy (9 posts)

  1. moikano
    Member
    Posted 3 years ago #

    I don't know if there is a good reason, but the breadcrumbs order is reversed with the terms of a hierarchical taxonomy (WP SEO 0.2.3.2).

    I solved by editing the function "get_term_parents()" in "wordpress-seo/frontend/class-breadcrumbs.php":

    function get_term_parents($term, $taxonomy) {
    	$origterm = $term;
    	$parents = array();
    	while ($term->parent != 0) {
    		$term = get_term($term->parent, $taxonomy);
    		if ($term != $origterm)
    			$parents[] = $term;
    	}
    	// editing start //
    	if ( count( $parents ) > 1 ) {
    		$parents = array_reverse( $parents );
    	}
    	// editing end //
    	return $parents;
    }

    If it is correct, I hope this change (or similar) will be applied in the next update.

    Thanks for the wonderful plugin!!! :-)

  2. Chris
    Member
    Posted 3 years ago #

    This only somewhat works. It works when you visit a category page that is deeply nested, but for single post pages the categories still appear backwards :/

  3. moikano
    Member
    Posted 3 years ago #

    Hi Chris,

    I suppose you're using WP SEO 0.2.5.4 (my report was for 0.2.3.2): if so, joostdevalk has updated partially the code... instead of to reverse the order in the get_term_parents() declaration, he reversed the order "directly" in the source, but not for tax/category/tag archives;

    to solve this, you can simply to edit the original "wordpress-seo/frontend/class-breadcrumbs.php" on row #234 so:

    [...]
    if ( is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0 ) {
    	$parents = $this->get_term_parents($term, $term->taxonomy);
    	// editing start //
    	$parents = array_reverse( $parents );
    	// editing end //
    
    	foreach($parents as $parent) {
    [...]

    I hope you can to solve it :)

  4. Chris
    Member
    Posted 3 years ago #

    Ahh, I see what you mean. I implemented your fix, and it seems to have worked, thanks so much!

    Strangely though, I've noticed that the only single post pages that display the entire breadcrumb path are posts filed under a third-level category within my "Music Reviews" category. Here is the category hierarchy I have set up...

    - Featured (for front page slideshow items)

    - Music
    ---- Music Interviews
    ---- Music News
    ---- Music Reviews
    -------- Albums
    -------- Concerts
    -------- EP's
    -------- Singles

    - Film
    ---- Film Interviews
    ---- Film News
    ---- Film Reviews

    Posts filed under second-level categories like "Film Interviews" or "Music News" do not display that category in the breadcrumb path, they simply display the parent category "Music" or "Film".

    Any ideas why this is happening? I can't seem to figure it out :/

  5. moikano
    Member
    Posted 3 years ago #

    Hi Chris,

    I'm glad you've solved :)

    about the other problem I don't know: are you sure that you didn't assign also parent categories to the post?

    to retrieve terms in the "main post type"'s taxonomy (specified in the WP SEO Internal Links options), WP SEO Breadcrumbs uses wp_get_object_terms() that returns a list of terms in alphabetical order: the first in the list is the "parent" category of the post;

    for example:
    - with "Music" and "Music News", "Music" is the post's "parent";
    - with "Music", "Music Reviews" and "Singles", "Music" is the post's "parent";
    - with "Music", "Music Reviews" and "Concerts", "Concerts" is the post's "parent";

    if this is your situation, the solution is very simple: assign posts to the "true" category only;

    I hope this answers your question :)

  6. Chris
    Member
    Posted 3 years ago #

    Ah! You've done it again! Haha. I had all of the parent categories assigned as well. I changed it so the posts were only assigned to their "true" or deepest categories, like you said, and everything works perfectly.

    Thanks so much for all of your help!

  7. Joost de Valk
    Member
    Plugin Author

    Posted 3 years ago #

    Thx moikano :)

  8. Jack
    Member
    Posted 3 years ago #

    I encountered the same thing. With the code of moikano I could correct the reverse order. Would be nice to be able to choose which order in the admin pages. Nice plugin by the way ;)

  9. Joost de Valk
    Member
    Plugin Author

    Posted 3 years ago #

    Just fixed the remaining sort issue as well.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic