• Thế giới của tôi
  • Công nghệ
  • Nghệ thuật
  • Giải trí
  • Chế tạo Diy
  • Video
  • Phòng trưng bày
  • Quảng cáo
Thế giới của tôi
  • Trang chủ
  • Công nghệ

    Bán hàng online hiệu quả qua Instagram

    Hướng dẫn trỏ tên miền Namesilo về VPS Vultr

    Trang web tạo mật khẩu ngẫu nhiên cực hay

    Hướng dẫn bật nén Gzip trong Nginx cực đơn giản

    Cấu hình plugin Wp Rocket hay

    Hướng dẫn trỏ tên miền Name về VPS Vultr

    Tên miền

    Bật tính năng của ảnh trong wordpress 3.0

    Tầm quan trọng hình ảnh sản phẩm trong bán hàng online

  • Nghệ thuật
  • Giải trí
  • Chế tạo Diy
  • Video
  • Phòng trưng bày
No Result
View All Result
  • Trang chủ
  • Công nghệ

    Bán hàng online hiệu quả qua Instagram

    Hướng dẫn trỏ tên miền Namesilo về VPS Vultr

    Trang web tạo mật khẩu ngẫu nhiên cực hay

    Hướng dẫn bật nén Gzip trong Nginx cực đơn giản

    Cấu hình plugin Wp Rocket hay

    Hướng dẫn trỏ tên miền Name về VPS Vultr

    Tên miền

    Bật tính năng của ảnh trong wordpress 3.0

    Tầm quan trọng hình ảnh sản phẩm trong bán hàng online

  • Nghệ thuật
  • Giải trí
  • Chế tạo Diy
  • Video
  • Phòng trưng bày
No Result
View All Result
Thế Giới Của Tôi
No Result
View All Result
Home Wordpress

Khai báo custom post type trong wordpress

Mai Linh by Mai Linh
20 Tháng Ba, 2023
3 min read
0
Share on FacebookShare on Twitter

Xem nhanh tại đây.

  1. Khai báo custom post type support fomat

Bữa giờ có anh em hỏi mình cách hiển thị lượt view bài viết như trên website của mình, thì nay mình xin chia sẻ với anh em cách làm nhé.

    1. Khai báo custom post type support fomat

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
add_action( 'init', 'create_custom_post_type' );
 
function create_custom_post_type() {
 
   $labels = array(
    'name' => __( 'Tax Liens' ),
    'singular_name' => __( 'Tax Lien' ),
    'all_items' => __('All Tax Liens'),
    'add_new' => _x('Add new Tax Lien', 'Tax Liens'),
    'add_new_item' => __('Add new Tax Lien'),
    'edit_item' => __('Edit Tax Lien'),
    'new_item' => __('New Tax Lien'),
    'view_item' => __('View Tax Lien'),
    'search_items' => __('Search in Tax Liens'),
    'not_found' =>  __('No Tax Liens found'),
    'not_found_in_trash' => __('No Tax Liens found in trash'),
    'parent_item_colon' => ''
    );
 
    $args = array(
    'labels' => $labels,
    'public' => true,
    'has_archive' => true,
    'menu_icon' => '',
    'rewrite' => array('slug' => 'taxlien'),
    'taxonomies' => array( 'category', 'post_tag' ),
    'supports'  => array( '<span style="color: #ff0000;">title', 'editor', 'thumbnail' , 'custom-fields', 'excerpt', 'comments', 'genesis-cpt-archives-settings</span>' )
    );
 
  register_post_type( 'tax_lien', $args);
}

Full example code ví dụ
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
add_action('init', function() {
    register_post_type('book', [
        'label' => __('Books', 'txtdomain'),
        'public' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-book',
        'supports' => ['title', 'editor', 'thumbnail', 'author', 'revisions', 'comments'],
        'show_in_rest' => true,
        'rewrite' => ['slug' => 'book'],
        'taxonomies' => ['book_author', 'book_genre'],
        'labels' => [
            'singular_name' => __('Book', 'txtdomain'),
            'add_new_item' => __('Add new book', 'txtdomain'),
            'new_item' => __('New book', 'txtdomain'),
            'view_item' => __('View book', 'txtdomain'),
            'not_found' => __('No books found', 'txtdomain'),
            'not_found_in_trash' => __('No books found in trash', 'txtdomain'),
            'all_items' => __('All books', 'txtdomain'),
            'insert_into_item' => __('Insert into book', 'txtdomain')
        ],        
    ]);
    register_taxonomy('book_genre', ['book'], [
        'label' => __('Genres', 'txtdomain'),
        'hierarchical' => true,
        'rewrite' => ['slug' => 'book-genre'],
        'show_admin_column' => true,
        'show_in_rest' => true,
        'labels' => [
            'singular_name' => __('Genre', 'txtdomain'),
            'all_items' => __('All Genres', 'txtdomain'),
            'edit_item' => __('Edit Genre', 'txtdomain'),
            'view_item' => __('View Genre', 'txtdomain'),
            'update_item' => __('Update Genre', 'txtdomain'),
            'add_new_item' => __('Add New Genre', 'txtdomain'),
            'new_item_name' => __('New Genre Name', 'txtdomain'),
            'search_items' => __('Search Genres', 'txtdomain'),
            'parent_item' => __('Parent Genre', 'txtdomain'),
            'parent_item_colon' => __('Parent Genre:', 'txtdomain'),
            'not_found' => __('No Genres found', 'txtdomain'),
        ]
    ]);
    register_taxonomy_for_object_type('book_genre', 'book');
    register_taxonomy('book_author', ['book'], [
        'label' => __('Authors', 'txtdomain'),
        'hierarchical' => false,
        'rewrite' => ['slug' => 'book-author'],
        'show_admin_column' => true,
        'labels' => [
            'singular_name' => __('Author', 'txtdomain'),
            'all_items' => __('All Authors', 'txtdomain'),
            'edit_item' => __('Edit Author', 'txtdomain'),
            'view_item' => __('View Author', 'txtdomain'),
            'update_item' => __('Update Author', 'txtdomain'),
            'add_new_item' => __('Add New Author', 'txtdomain'),
            'new_item_name' => __('New Author Name', 'txtdomain'),
            'search_items' => __('Search Authors', 'txtdomain'),
            'popular_items' => __('Popular Authors', 'txtdomain'),
            'separate_items_with_commas' => __('Separate authors with comma', 'txtdomain'),
            'choose_from_most_used' => __('Choose from most used Authors', 'txtdomain'),
            'not_found' => __('No Authors found', 'txtdomain'),
        ]
    ]);
    register_taxonomy_for_object_type('book_author', 'book');
});

URL xem thêm https://codepen.io/ajjujaiswal/pen/rKLdLz

Chúc các bạn thành công.

Previous Post

Slider đẹp cho website- Copy

Next Post

Hướng dẫn tạo bài viết con trong bài viết tùy chỉnh full frame theme wp

Mai Linh

Mai Linh

chuyên wordpress, function, php, code, ...

Next Post

Cách tạo vị trí menu wordpress

No Result
View All Result

Bài viết mới

  • Một mẫu slider đẹp
  • Cách tạo vị trí menu wordpress
  • Khai báo custom post type trong wordpress
  • Sửa lỗi Because app requires SDK version >=2.15.1 <3.0.0 version solving failed
  • Cách đặt nhân vật tiếng trung phồn thể cho game Jx3 Quốc tế

Phản hồi gần đây

    Chuyên mục

    • Bảo mật website
    • Bẻ khóa theme plugin
    • Cắt giấy
    • Chụp ảnh
    • Chụp ảnh sản phẩm
    • Code tiện ích cho website
    • Code trang trí mở rộng
    • Công cụ Tools
    • Công nghệ
    • CSS
    • Digital Marketing
    • Function
    • Game Jx2
    • Game Jx3
    • Game Online
    • Gian hàng online
    • Hosting
    • HTML
    • Instagram
    • Kirigami
    • Kirigami 0 độ
    • Kirigami 180 độ
    • Kirigami 360 độ
    • Kirigami 90 độ
    • Mã độc hại website
    • Marketing Online
    • Máy chủ ảo VPS
    • Origami
    • Paper Craft
    • Phần mềm máy tính cơ bản
    • Php
    • Quilling
    • SEO
    • SEO Offpage
    • SEO Onpage
    • Share theme plugin
    • Shopee
    • Sửa ảnh
    • Tăng doanh thu bán hàng
    • Tên miền
    • Thông tin thế giới của tôi
    • Tối ưu tốc độ web
    • Windows
    • Wordpress

    Recent News

    Một mẫu slider đẹp

    29 Tháng Sáu, 2023

    Cách tạo vị trí menu wordpress

    20 Tháng Tư, 2023
    • Giới thiệu
    • Quảng cáo
    • Bảo mật
    • Liên hệ

    © 2019 Thế Giới Của Tôi - Thiết kế & xây dựng bởi Ngôi Nhà Web.vn.

    No Result
    View All Result
    • Thế giới của tôi
    • Công nghệ
    • Nghệ thuật
    • Giải trí
    • Chế tạo Diy
    • Video
    • Phòng trưng bày
    • Quảng cáo

    © 2019 Thế Giới Của Tôi - Thiết kế & xây dựng bởi Ngôi Nhà Web.vn.