Thứ tự sử dụng file của themes WordPress
Nếu bạn đã từng làm (hoặc nghiên cứu) themes cho WordPress hẳn bạn đã biết tới thứ tự sử dụng file của themes WordPress. Ví dụ để thể hiện một bài blog bạn có thể để mã ngay trong index.php hoặc tạo riêng single.php, cao hơn nữa, để hiển thì bài blog ở các post type khác nhau, bạn có thể đặt tên file theo kiểu single-{pos-type}.php. Vậy làm sao để biết cách đặt tên file? Dưới đây là danh sách thứ tự và cách đặt tên trong WordPress 3 theme.
*
404
404.php
index.php
*
Search
search.php
index.php
*
Home
home.php
index.php
*
Single
single-{post-type}.php - Nếu post_type là videos, WordPress sẽ tìm single-videos.php.
single.php
index.php
*
Page
custom_template.php - Bạn có thể xem thêm Custom template tại đây
page-{slug}.php - Nếu page slug là recent-news, thì WordPress sẽ tìm page-recent-news.php
page-{id}.php - Nếu page có id là 6, thì WordPress sẽ tìm page-6.php
page.php
index.php
*
Archive
archive.php
index.php
*
Category
category-{slug}.php - Nếu category là ntuts, thì WordPress sẽ tìm category-ntuts.php
category-{id}.php - Nếu category có id là 6, thì WordPress sẽ tìm tagcategory6.php
category.php
archive.php
index.php
*
Tags
tag-{slug}.php - Nếu tag slug là ntuts, thì WordPress sẽ tìm tag-ntuts.php
tag-{id}.php - Nếu tag slug có id là 6, thì WordPress sẽ tìm tag-6.php
tag.php
archive.php
index.php
*
Taxonomies
taxonomy-{tax}-{term}.php - Nếu taxonomy là ntuts, và slug là design thì WordPress sẽ tìm taxonomy-ntuts-design.php
taxonomy-{tax}.php - Hoặc bạn chỉ cần đặt tên taxonomy-ntuts.php
taxonomy.php
archive.php
index.php
Author
author-{nicename}.php - Nếu tên tác giả là Neo, WordPress sẽ tìm author-neo.php
author-{id}.php - Nếu tác giả có id là 6, WordPress sẽ tìm author-6.php
author.php
archive.php
index.php
*
Attachment
mime.php
type.php
mime_type.php
attachment.php
single.php
index.php
*
Date
date.php
archive.php
index.php
0 nhận xét: