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é.
-
-
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.








