最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Using the_title() and fetching the parent page's title and slug to construct breadcrumbs

matteradmin8PV0评论

I'm trying to construct a breadcrumb trail where some of the paths consist of parent/child custom post types.

For example:

else if ( is_singular( 'resort' ) ) {
    global $post;
    $post_data = get_post($post->post_parent);
    $parent_title = $post_data->post_title;
    $parent_slug = $post_data->post_name;

    echo '<li><a href="/destinations/" title="' . __('Destinations', 'bookyourtravel') . '">' . __('Destinations', 'bookyourtravel') . '</a></li>';
    echo '<li><a href="/destinations/' . $parent_slug . '/" title="' . $parent_title . ' Villas">' . $parent_title . '</li>';
}

Whilst this outputs exactly what I'm after, for example:

Destinations > $parent_title

When I try to get the current page's title for the last path in the breadcrumb simply with:

echo "<li>";
echo the_title();
echo "</li>";

It ends up duplicating the second destination > $parent_title path above...

I attach a screenshot of the source code to illustrate this problem.

It seems by the usage of the_title(), it seems to wrap any mention of the current page title (Playa Blanca) in a link which links back to the parent page (Lanzarote) which hopefully can be seen in the image.

Why can't the above just echo the current page title (the_title()) at the end of the breadcrumb trail properly?

I just want 'Playa Blanca' to be at the end of the breadcrumb trail not linked and not interfering with anything else on the page.

Post a comment

comment list (0)

  1. No comments so far