Trong quá trình custom flatsome nó sẽ không show breadcrumb cho anh chị, bài viết hôm nay tôi sẽ chia sẽ cách làm:
Mở file function lên thêm code sau vào:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
<?php add_action("flatsome_after_header",array($this,"add_breadcrumb"),12); function add_breadcrumb(){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if (is_plugin_active('woocommerce/woocommerce.php')){ if(!is_front_page() && !is_shop() && !is_product_category()){ ?> <div class="page-title shop-page-title product-page-title"> <div class="page-title-inner flex-row medium-flex-wrap container"> <div class="flex-col flex-grow medium-text-center"> <div class="is-large"> <?php flatsome_breadcrumb(); ?> </div> </div> </div> </div> <?php } }else{ if(!is_front_page()){ ?> <div class="page-title shop-page-title product-page-title"> <div class="page-title-inner flex-row medium-flex-wrap container"> <div class="flex-col flex-grow medium-text-center"> <div class="is-large"> <?php breadcrumb(); ?> </div> </div> </div> </div> <?php } } } function breadcrumb(){ if(!is_front_page()): $breadcrumb=array(); //Home $breadcrumb_item=array( 'url' => home_url(), 'title' => __('Trang chủ','chilitheme') ); array_push($breadcrumb,$breadcrumb_item); //at singular template if(is_singular() && !is_singular('product') && !is_page()): global $post; //Term $taxonomy_names = get_object_taxonomies($post); //var_dump(get_post_type()); $term_arr=array(); $terms = get_the_terms( $post->ID, $taxonomy_names[0] ); if($terms): foreach ( $terms as $term ): //get parent term top $term_parent_arr=get_ancestors($term->term_id,$taxonomy_names[0]); if($term_parent_arr): foreach($term_parent_arr as $item): $term_item = get_term($item,$taxonomy_names[0]); if($term_item->parent == 0): array_push($term_arr,$item); break; endif; endforeach; endif; array_push($term_arr,$term->term_id); endforeach; endif; $term_arr = array_unique($term_arr); if($term_arr): foreach($term_arr as $item): $term = get_term($item,$taxonomy_names[0]); $breadcrumb_item=array( 'url' => get_term_link( (int) $term->term_id,$taxonomy_names[0]), 'title' => $term->name ); array_push($breadcrumb,$breadcrumb_item); endforeach; endif; //singular $breadcrumb_item=array( 'url' => get_permalink($post->ID), 'title' => $post->post_title ); array_push($breadcrumb,$breadcrumb_item); endif; //page if(is_page()): global $post; $breadcrumb_item=array( 'url' => get_permalink($post->ID), 'title' => $post->post_title ); array_push($breadcrumb,$breadcrumb_item); endif; //blog if(is_home()): $page_for_posts=get_option('page_for_posts'); $breadcrumb_item=array( 'url' => get_permalink($page_for_posts), 'title' => __('Blog','chilitheme') ); array_push($breadcrumb,$breadcrumb_item); endif; //at taxonomy template if((is_tax() || is_category()) && !is_tax('product_cat')): global $wp_query; $term = $wp_query->get_queried_object(); $term_arr=array(); //get parent term top $taxonomy_names = get_object_taxonomies('post'); $term_parent_arr=get_ancestors($term->term_id,$taxonomy_names[0]); if($term_parent_arr): foreach($term_parent_arr as $item): $term_item = get_term($item,$taxonomy_names[0]); if($term_item->parent == 0): array_push($term_arr,$item); break; endif; endforeach; endif; array_push($term_arr,$term->term_id); $term_arr = array_unique($term_arr); if($term_arr): foreach($term_arr as $item): $term = get_term($item,$taxonomy_names[0]); $breadcrumb_item=array( 'url' => get_term_link( (int) $term->term_id,$taxonomy_names[0]), 'title' => $term->name ); array_push($breadcrumb,$breadcrumb_item); endforeach; endif; endif; if(is_post_type_archive()): $get_current_post_type=get_post_type(); $archive=get_post_type_object($get_current_post_type); //var_dump($archive); $breadcrumb_item=array( 'url' => get_post_type_archive_link($get_current_post_type), 'title' => $archive->labels->menu_name ); array_push($breadcrumb,$breadcrumb_item); endif; endif; if($breadcrumb): ?> <div id="breadcrumb-new"><ul> <?php foreach($breadcrumb as $item):?> <li class="next"><a href="<?php echo $item['url']; ?>" title="<?php echo $item['title']; ?>"><span><?php echo $item['title']; ?></span></a></li> <?php endforeach; ?> </ul></div> <?php endif; ?> <?php } |
Mở file style.css (lưu ý bạn phải load FontAwesome nha)
bỏ code sau vào:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
div#breadcrumb-new ul li { display: inline-block; list-style: none; position: relative; padding-right: 12px; margin-right: 6px; margin-left: 0; } div#breadcrumb-new ul li::after { content: "\f105"; font-family: FontAwesome; position: absolute; top: 0; right: 0; } div#breadcrumb-new ul li:last-child::after { content: none; } |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress