About order of single posts breadcrumb


Hi everyone. I would like to hear your opinion about "function beans_breadcrumb() ". Now, the order in which breadcrumbs are displayed is not the relationship between parents and children.

For example Home / Baseball / Sports / NY Mets

I thought that it would be better to change the order from parent to child. And I wrote the code for that.

    // Single posts.
    if ( is_single() && 'post' == $post_type ) {

        $categories_id = array();
        $categories_term = array();

        $categories = get_the_category($post->ID);
        $cat = $categories[0];

        if($cat -> parent != 0){
            $ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));
            foreach($ancestors as $ancestor){
            $categories_id[] = $ancestor;
            }
        }

        $categories_id[] = $categories[0]->cat_ID;

        foreach ($categories_id as $categories_ids) {
            $categories_term[] = get_term( $categories_ids, 'category');
        }

        foreach ( $categories_term as $category ) {
            $breadcrumbs[ get_category_link( $category->term_id ) ] = $category->name;
        }

        $breadcrumbs[] = get_the_title();

    } elseif ......

If you use this code, it will be as follows.

Home / Sports / Baseball / NY Mets

Which do you think will get good results for usability and SEO?

Thanks

Write a reply

Login or register to write a reply, it's free!