Tạo thêm Breadcrumbs cho chuyên mục Category Blog theme Flatsome?

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi seolagi, 6/1/21.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,029
    Đã được thích:
    81
    Điểm thành tích:
    48
    Cho mình hỏi cách tạo thêm Breadcrumbs cho chuyên mục category của blog themes flatsome thì như thế nào vậy? hiện tại nó chỉ có mỗi tiêu đề mà không có thêm tab Breadcrumbs ví dụ: trang chủ -> tin tức.

    Giờ muốn thêm Breadcrumbs thì làm như thế nào bạn nào biết chỉ giúp mình với. Có code nào chèn ở function.php thì càng tốt, vì hướng dẫn ở bên trong sâu quá mình không rành code không biết.

    Cảm ơn mọi người
     
    Cảm ơn đã xem bài:

    Tạo thêm Breadcrumbs cho chuyên mục Category Blog theme Flatsome?

  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,904
    Đã được thích:
    1,199
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Của bạn đây nhé, chèn vào function.php của themes.
    PHP:
    function get_flatsome_blog_breadcrumbs() {
        
    $delimiter '<span class="divider">&#47;</span>';
        
    $home 'Trang chủ';
        
    $before '';
        
    $after '';
        if ( !
    is_home() && !is_front_page() || is_paged() ) {
            echo 
    '<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-medium">';
            echo 
    '<nav class="breadcrumbs">';
            global 
    $post;
            
    $homeLink get_bloginfo('url');
            echo 
    '<a href="' $homeLink '">' $home '</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);
                if (
    $thisCat->parent != 0) echo(get_category_parents($parentCatTRUE' ' $delimiter ' '));
                echo 
    $before single_cat_title(''false) . $after;
            } elseif ( 
    is_day() ) {
                echo 
    '<a href="' get_year_link(get_the_time('Y')) . '">' get_the_time('Y') . '</a> ' $delimiter ' ';
                echo 
    '<a href="' get_month_link(get_the_time('Y'),get_the_time('m')) . '">' get_the_time('F') . '</a> ' $delimiter ' ';
                echo 
    $before get_the_time('d') . $after;
            } elseif ( 
    is_month() ) {
                echo 
    '<a href="' get_year_link(get_the_time('Y')) . '">' get_the_time('Y') . '</a> ' $delimiter ' ';
                echo 
    $before get_the_time('F') . $after;
            } elseif ( 
    is_year() ) {
                echo 
    $before get_the_time('Y') . $after;
            } elseif ( 
    is_single() && !is_attachment() ) {
                if ( 
    get_post_type() != 'post' ) {
                    
    $post_type get_post_type_object(get_post_type());
                    
    $slug $post_type->rewrite;
                    echo 
    '<a href="' $homeLink '/' $slug['slug'] . '/">' $post_type->labels->singular_name '</a> ' $delimiter ' ';
                    echo 
    $before get_the_title() . $after;
                } else {
                    
    $cat get_the_category(); $cat $cat[0];
                    echo 
    get_category_parents($catTRUE' ' $delimiter ' ');
                    echo 
    $before get_the_title() . $after;
                }
            } elseif ( !
    is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
                
    $post_type get_post_type_object(get_post_type());
                echo 
    $before $post_type->labels->singular_name $after;
            } elseif ( 
    is_attachment() ) {
                
    $parent get_post($post->post_parent);
                
    $cat get_the_category($parent->ID); $cat $cat[0];
                echo 
    get_category_parents($catTRUE' ' $delimiter ' ');
                echo 
    '<a href="' get_permalink($parent) . '">' $parent->post_title '</a> ' $delimiter ' ';
                echo 
    $before get_the_title() . $after;
            } elseif ( 
    is_page() && !$post->post_parent ) {
                echo 
    $before get_the_title() . $after;
            } elseif ( 
    is_page() && $post->post_parent ) {
                
    $parent_id $post->post_parent;
                
    $breadcrumbs = array();
                while (
    $parent_id) {
                    
    $page get_page($parent_id);
                    
    $breadcrumbs[] = '<a href="' get_permalink($page->ID) . '">' get_the_title($page->ID) . '</a>';
                    
    $parent_id $page->post_parent;
                }
                
    $breadcrumbs array_reverse($breadcrumbs);
                foreach (
    $breadcrumbs as $crumb) echo $crumb ' ' $delimiter ' ';
                echo 
    $before get_the_title() . $after;
            } elseif ( 
    is_search() ) {
                echo 
    $before 'Search results for "' get_search_query() . '"' $after;
            } elseif ( 
    is_tag() ) {
                echo 
    $before 'Posts tagged "' single_tag_title(''false) . '"' $after;
            } elseif ( 
    is_author() ) {
                global 
    $author;
                echo 
    $before 'Articles posted by ' $userdata->display_name $after;
            } elseif ( 
    is_404() ) {
                echo 
    $before 'Error 404' $after;
            }
            if ( 
    get_query_var('paged') ) {
                if ( 
    is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
                echo 
    __('Page') . ' ' get_query_var('paged');
                if ( 
    is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
            }
            echo 
    '</nav>';
            echo 
    '</div></div></div></div>';
        }
    }
    add_action'flatsome_before_blog' 'get_flatsome_blog_breadcrumbs');
     
  3. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,029
    Đã được thích:
    81
    Điểm thành tích:
    48
    Dạ em cảm ơn ạ, đúng cái em cần, đẹp lung linh đầy đủ rồi ạ
     


Chủ để tương tự : Tạo thêm
Diễn đàn Tiêu đề Date
Mã nguồn mở Wordpress Code Tạo danh sách tác giả trong themes NewsPaper của Wodpress 1/9/20
Mã nguồn mở Wordpress Xin code tự động tạo user trong function.php wordpress 6/10/23
Mã nguồn mở Wordpress Lỗi khi tạo subfolder website wordpress, subfolder web vào mục con không được 26/6/23
Mã nguồn mở Wordpress Tạo Popup đặt hàng từ Contact Form 7 Wordpress 13/4/22
Mã nguồn mở Wordpress Tạo trang cảm ơn sau khi submit trong Contact form 7 như thế nào? 6/1/22