Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumb item schema position appears in reverse order #110

Closed
shazzad opened this issue Jun 13, 2020 · 1 comment
Closed

Breadcrumb item schema position appears in reverse order #110

shazzad opened this issue Jun 13, 2020 · 1 comment
Assignees

Comments

@shazzad
Copy link

shazzad commented Jun 13, 2020

Issue

Breadcrumb item's position meta is coming in reverse order. It gets reversed after the home & docs item.

Reference

https://github.com/tareq1988/wedocs-plugin/blob/81c8f74eb660d5030c5d9a5d5c31d310cb3581ae/includes/functions.php#L106-L124

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.

@Rubaiyat-E-Mohammad
Copy link

Could not regenerate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants