Dùng hàm sau thêm vào function.php để tạo beadcrumb theo cấu trúc danh mục cha ,con cho wordpress nhé
function codfe_get_blog_breadcrumbs() {
if (!is_home()) {
$html ='';
$html.= '<a href="';
$html.= get_option('home');
$html.= '"> Trang chủ</a> » ';
if (is_category() || is_single()) {
$cats=get_the_category();
$cid=array();
foreach($cats as $cat) { $cid[]=$cat->cat_ID; }
$cid=implode(',', $cid);
foreach((get_categories('orderby=term_group&include='.$cid)) as $category) { // notice orderby
$html.= '<a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name.'</a> » '; // keep a space after </a> as seperator
}
$html = substr($html,0,-3);
//the_category(' + ');
if (is_single()) {
//echo " » ";
//the_title();
}
} elseif (is_page()) {
$html.= the_title();
}
echo $html;
}
}
Lưu ý: hảm get_categories(‘orderby=term_group&include=’.$cid) còn có thể sort theo các tiêu chí sau:
id name - default slug count term_group
Để hiển thị ra chúng ta có thể hook vào trong post của flatsome như sau (thêm vào function.php)
add_action( 'flatsome_before_blog' , 'codfe_get_blog_breadcrumbs', 20 );
hoặc tạo shortcode để hiển thị vị trí cần thiết (thêm vào function.php)
add_shortcode('breadrummenu', 'codfe_get_blog_breadcrumbs' );
Hiển thị shortcode bằng cách thêm hoặc trong php thì dùng như sau:
echo do_shortcode('[breadrum-menu]');
Chúc các bạn thành công nhé!
Bài viết mới:
- Danh sách các tài nguyên dành cho thiết kế web & đồ họa
- Truy tìm vị trí của laptop bị mất với Find My Device của Windows 10
- Rozrywka online i szeroki wybór gier kasynowych czeka na graczy na vavadas1.pl każdego dnia
- Code thêm Fanpage Facebook vào web
- Khắc phục lỗi image file unicode wordpress – clear image file name wordpress
