What is breadcrumb navigation?
Bread crumbs usually appear at the top of the page, usually below the title or page header. It provides users with links to any previous page (these links are also paths to the current page), which is usually the parent page of this page in the hierarchical structure.
It can also be understood that breadcrumbs provide users with a quick way to trace back to the home page or portal page of the website, and most of them look like this: home page → classified page → secondary classified page.
For example, this article of Lightning Blog belongs to: Home Page >; WordPress
Advantages of breadcrumb navigation on web pages
1. can provide multi-path interaction, which is convenient for users to jump to other pages. It is especially useful in websites with many pages and classifications.
2. The breadcrumb navigation information structure is also of great benefit to the seo of the website, which can emphasize the keywords of the website more and expand the scope of keywords, thus achieving better optimization purposes.
3. It shows the information structure and collection method of the information set from one side, which can let users find what they need in the fastest time.
Of course, it can be implemented by plug-ins. This article mainly talks about the traditional code method.
Method 1: breadcrumb navigation can be realized by directly adding code to relevant pages.
Add the following code directly to the position where you want breadcrumb navigation to appear.
< div class="mbx-dh">
< a href="< ? php bloginfo(‘url’); ? >" > < ? php bloginfo(‘name’); ? > < /a> ?
< ? php
if( is_single() ){
$categorys = get_the_category();
$category = $categorys[0];
echo( get_category_parents($category-> term_id,true,’ ? ‘) );
the_title();
} elseif ( is_page() ){
the_title();
} elseif ( is_category() ){
single_cat_title();
} elseif ( is_tag() ){
single_tag_title();
} elseif ( is_day() ){
The _ time ('Fj Day of Year Y');
} elseif ( is_month() ){
The _ time ('y year F');
} elseif ( is_year() ){
The _ time ('y year');
} elseif ( is_search() ){
Echo $s.' s search results';
}
>
< /div>
You can add these codes to header.php, or you can put them on the navigation title of single.php page. The pages you may need to add may include: archive.php, archives.php, links.php and page.php.
Method 2: The breadcrumb navigation effect is realized through functions.php call.
First add the following code to the theme's functions.php file:
function dimox_breadcrumbs() {
$delimiter = ‘?’ ;
$name = ‘Home’; //text for the ‘Home’ link
$currentBefore = ‘< span>’ ;
$currentAfter = ‘< /span>’ ;
if ( ! is_home() & & ! is_front_page() || is_paged() ) {
echo ‘< div id="crumbs">’ ;
global $post;
$home = get_bloginfo(‘url’);
echo ‘< a href="’ . $home . ‘"> ’ . $name . ‘< /a> ‘ . $delimiter . ‘ ‘;
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query-> get_queried_object();
$thisCat = $cat_obj-> term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat-> parent);