dhaka wordpress meetup 3 - presentation for template hierarchy
DESCRIPTION
TRANSCRIPT
19 July 2013
WordPress Template Hierarchy
Presented by
Dhaka WordPress Meetup 3
oneTarek.comMd Jahidul Islam(oneTarek)
The Question
How can I show different style and layout for different type pages like Home, Single,
Pages, Category, Tag, Taxonomy, Attachment etc.
The Answer 1
Hard Way
We can use various conditional tagsto detect what kind of page has been displayed currently
In header.php we can use
if(is_home()){load styles and layout for homepage}
elseif(is_single()){load styles and layout for single page}
And so on..
Some Conditional Tagsis_home(), is_single(), is_page(),is_tag(),
is_category(), is_author(), is_404() and more...
The Answer 2Easy and Best Way
WordPress loads different theme files
to display different types of pages
The Question
What file(s) does WordPress use when it displays a certain type of page?
The Answer?
Read Detail :
codex.wordpress.org/Template_Hierarchy
Template Hierarchy
Lets start with the basics
header.php
footer.php
sidebar.php
The Loop
A working theme needs:
index.php + style.css =
A very basic but functional theme
So what is with all of this then?
A: Different looks for different types of content
home.php
Home Page Display Rules 12index.php
front-page.phpThis is used for displaying your latest posts or a static page as defined in Settings > Reading
Front or Home page
3
12Page Display Rules
When you set the Front page in Settings> Reading
Home Page Display RulesWhen posts page is set in the Front Page displays section of Settings> Reading
4
Custom Template FileThe page template assigned to the page<?php/* Template Name: Whatever you call your template*/?>
Page Display Rules
page.php
3
12
page-{slug}.phpif you use the slug “ bananas” WordPress will look for page-bananas.php
page-{id}.phpif the page ID is 4, Wordpress looks to use page-4.php
5index.php
Single Post Page
Singular Page12Static page
Attachment post
Singlular page
Single post
3
12Custom Post
Blog post
4
MIME-type.phpIt can be any MIME type ( video.php, image.php, etc) for text/plain in order:1.text.php2.plain.php3.text_plain.php
Singular Post
single.php
Single Post- Attachment 3
12attachment.php
single-attachment.php
5index.php
single-{posttype}.phpif post type was “movies”, WordPress would look for single-movies.php
Singular Post single.php
Single Post- Custom Post
3
12
index.php
single-post.php
Singular Post single.php
Single Post- Blog Post
3
12
index.php
4
Custom Template FileThe page template assigned to the page<?php/* Template Name: Whatever you call your template*/?>
Singular Page
page.php
3
12
page-{slug}.phpif you use the slug “ bananas” WordPress will look for page-bananas.php
page-{id}.phpif the page ID is 4, Wordpress looks to use page-4.php
5index.php
Static page-aka
“ Page Display Rules”
Post Pages
Category PagesTag PagesCustom Post Types
Archive Pages
Date Pages3
1
2Author Pages
Category Pages Tag Pages Author Pages Date Pages
4
3
1
2
5
1tag-{slug}.php
tag-{id}.php
tag.php
archive.php
index.php
4
3
2
5
1category-{slug}.phpcategory-{id}.php
category.php
archive.php
index.php
4
3
2
5
1author-{nicename}.phpauthor-{id}.php
author.php
archive.php
index.php
3
2
1date.php
archive.php
index.php
Custom Post Type Pages
3
2
1archive-{post-type}.php
archive.php
index.php
Category Pages from Tag Pages
Why learn this?Category from Category
Differentiate Content Types
3
12
Category from Pages
4 Pages
uestion?Qany
THANKSFOR YOUR ATTENTION
Contact
Website: onetarek.com
Facebook.com/oneTarek
Twitter.com/oneTarek
WordPress : oneTarek
Md Jahidul Islam(oneTarek)