Breadcrumb item schema position appears in reverse order
shazzad opened this issue · 1 comments
shazzad commented
Issue
Breadcrumb item's position meta is coming in reverse order. It gets reversed after the home & docs item.
Reference
Outcome
<ol class="wedocs-breadcrumb" itemscope="" itemtype="http://schema.org/BreadcrumbList">
<li><i class="wedocs-icon wedocs-icon-home"></i></li>
<li itemprop="itemListElement" ...>
<a itemprop="item" href="...">
<span itemprop="name">Home</span></a>
<meta itemprop="position" content="1">
</li>
<li class="delimiter">...</li>
<li itemprop="itemListElement" ...>
<a itemprop="item" href="...">
<span itemprop="name">Docs</span></a>
<meta itemprop="position" content="2">
</li>
<li class="delimiter">...</li>
<li itemprop="itemListElement" ...>
<a itemprop="item" href="...">
<span itemprop="name">Level 1</span></a>
<meta itemprop="position" content="5">
</li>
<li class="delimiter">...</li>
<li itemprop="itemListElement" ...>
<a itemprop="item" href="...">
<span itemprop="name">Level 2</span></a>
<meta itemprop="position" content="4">
</li>
<li class="delimiter">...</li>
<li itemprop="itemListElement" ...>
<a itemprop="item" href="...">
<span itemprop="name">Level 3</span></a>
<meta itemprop="position" content="3">
</li>
<li class="delimiter">...</li>
<li><span class="current">Test Sub Article</span></li>
</ol>
Possible solution
if ( 'docs' == $post->post_type && $post->post_parent ) {
$parent_id = $post->post_parent;
$pages = [];
while ( $parent_id ) {
$page = get_post( $parent_id );
$parent_id = $page->post_parent;
$pages[] = $page;
}
$pages = array_reverse( $pages );
foreach ( $pages as $page ) {
++$breadcrumb_position;
$html .= wedocs_get_breadcrumb_item( get_the_title( $page->ID ), get_permalink( $page->ID ), $breadcrumb_position );
$html .= ' ' . $args['delimiter'] . ' ';
}
}
Thanks.