Skip to the content.

THE WORDPRESS TEMPLATE HIERARCHY

Đây là hệ thống cấp bật của template được wordpress quy định nhớ tuân thủ hen.

index.php
├──archive.php
│  ├──author.php                           Author Archive
│  │  └──author-$id.php                    Author Archive With ID
│  │     └──author-$nicename.php           Author Archive With Nicename
│  ├──category.php                         Category Archive
│  │  └──category-$id.php                  Category Archive With ID
│  │     └──category-$slug.php             Category Archive With Slug
│  ├──archive-$posttype.php                Custom Post Type Archive
│  ├──taxonomy.php                         Custom Taxonomy Archive
│  │  └──taxonomy-$taxonomy.php            Custom Taxonomy Archive
│  │     └──taxonomy-$taxonomy-$term.php   Custom Taxonomy Archive
│  ├──date.php                             Date Archive
│  └──tag.php                              Tag Archive
│     └──tag-$id.php                       Tag Archive With ID
│        └──tag-$slug.php                  Tag Archive With Slug
├──singular.php                            Singular Page
│  ├──single.php                           Single Post Page
│  │  ├──attachment.php                    Attachment Post
│  │  │  └──$mimetype.php                  Attachment Post
│  │  │     └──$subtype.php                Attachment Post
│  │  │        └──$mimetype-$subtype.php   Attachment Post
│  │  ├──single-$posttype.php              Custom Post
│  │  │  └──single-$posttype-$slug.php     Custom Post
│  │  └──single-post.php                   Blog Post
│  └──page.php                             Static Page
│     └──page-$id.php                      Static Page With ID
│        └──page-$slug.php                 Static Page With Slug
├──home.php                                Blog Posts Index Page
│  └──front-page.php                       Site Front Page
├──404.php                                 Error 404 Page
└──search.php                              Search Result Page

Giải thích

Chúng ta có các dạng: Archive: Đây là layout dùng để show ra danh sách các bài viết (Post).

Wordpress sẽ tìm các file con nếu không tồn tại nó sẽ tìm tới file cấp cao hơn để hiển thị. Về tính quan trọng các file nằm gần gốc sẽ buộc phải có. Ví dụ: Trang sample có id là 1, slug là sample và url là https://themestandard.com/sample thì khi truy cập nó sẽ tìm đến template theo thứ tự từ ① > ② > ③ > ④ > ⑤.

index.php                    ⑤
├──singular.php              ④
│  └──page.php               ③
│     └──page-$id.php        ②
│        └──page-$slug.php   ①

Tham khảo

Navigation