19 July 2013
WordPress Template
Hierarchy
Presented by
Dhaka WordPress Meetup 3
oneTarek.com
Md Jahidul Islam(oneTarek)
The
Question
How can I show different style and layout
for different type pages like Home, Single,
Pages, Category, Tag,
T...
The
Answer 1
Hard Way
We can use various conditional tags
to detect what kind of page
has been displayed currently
In head...
The
Answer 2
Easy 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 1
2index.php
front-page.php
This is used for displaying your latest posts or a static page as
defined in Settings > Reading
Front or Ho...
4
Custom Template File
The page template assigned to the page
<?php
/* Template Name: Whatever you call your template*/
?>...
Single Post Page
Singular Page
1
2Static page
Attachment post
Singlular page
Single post
3
1
2Custom Post
Blog post
4
MIME-type.php
It can be any MIME type ( video.php, image.php, etc) for
text/plain in order:
1.text.php
2.plain.php
3.tex...
single-{posttype}.php
if post type was “movies”, WordPress would look for
single-movies.php
Singular Post single.php
Singl...
single-post.php
Singular Post single.php
Single Post- Blog Post
3
1
2 index.php
4
Custom Template File
The page template assigned to the page
<?php
/* Template Name: Whatever you call your template*/
?>...
Post Pages
Category Pages
Tag Pages
Custom Post Types
Archive Pages
Date Pages
3
1
2Author Pages
Category Pages Tag Pages Author Pages Date Pages
4
3
1
2
5
1 tag-{slug}.php
tag-{id}.php
tag.php
archive.php
index.php
4
3...
Category Pages from Tag Pages
Why learn this?
Category from Category
Differentiate Content Types
3
1
2
Category from Pages...
uestion?
Qany
THANKS
FOR YOUR
ATTENTION
Contact
Website: onetarek.com
Facebook.com/oneTarek
Twitter.com/oneTarek
WordPress : oneTarek
Md...
Upcoming SlideShare
Loading in...5
×

Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

7,124

Published on

Published in: Technology
1 Comment
9 Likes
Statistics
Notes
  • It was really a nice presentation. Thanks Jahid vhai.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,124
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
120
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide

Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

  1. 1. 19 July 2013 WordPress Template Hierarchy Presented by Dhaka WordPress Meetup 3 oneTarek.com Md Jahidul Islam(oneTarek)
  2. 2. The Question How can I show different style and layout for different type pages like Home, Single, Pages, Category, Tag, Taxonomy, Attachment etc.
  3. 3. The Answer 1 Hard Way We can use various conditional tags to 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 Tags is_home(), is_single(), is_page(),is_tag(), is_category(), is_author(), is_404() and more...
  4. 4. The Answer 2 Easy and Best Way WordPress loads different theme files to display different types of pages
  5. 5. The Question What file(s) does WordPress use when it displays a certain type of page?
  6. 6. The Answer? Read Detail : codex.wordpress.org/Template_Hierarchy Template Hierarchy
  7. 7. Lets start with the basics header.php footer.php sidebar.php The Loop
  8. 8. A working theme needs: index.php + style.css = A very basic but functional theme
  9. 9. So what is with all of this then? A: Different looks for different types of content
  10. 10. home.php Home Page Display Rules 1 2index.php
  11. 11. front-page.php This is used for displaying your latest posts or a static page as defined in Settings > Reading Front or Home page 3 1 2 Page Display Rules When you set the Front page in Settings> Reading Home Page Display Rules When posts page is set in the Front Page displays section of Settings> Reading
  12. 12. 4 Custom Template File The page template assigned to the page <?php /* Template Name: Whatever you call your template*/ ?> Page Display Rules page.php 3 1 2 page-{slug}.php if you use the slug “ bananas” WordPress will look for page- bananas.php page-{id}.php if the page ID is 4, Wordpress looks to use page-4.php 5index.php
  13. 13. Single Post Page Singular Page 1 2Static page
  14. 14. Attachment post Singlular page Single post 3 1 2Custom Post Blog post
  15. 15. 4 MIME-type.php It can be any MIME type ( video.php, image.php, etc) for text/plain in order: 1.text.php 2.plain.php 3.text_plain.php Singular Post single.php Single Post- Attachment 3 1 2attachment.php single-attachment.php 5index.php
  16. 16. single-{posttype}.php if post type was “movies”, WordPress would look for single-movies.php Singular Post single.php Single Post- Custom Post 3 1 2 index.php
  17. 17. single-post.php Singular Post single.php Single Post- Blog Post 3 1 2 index.php
  18. 18. 4 Custom Template File The page template assigned to the page <?php /* Template Name: Whatever you call your template*/ ?> Singular Page page.php 3 1 2 page-{slug}.php if you use the slug “ bananas” WordPress will look for page- bananas.php page-{id}.php if the page ID is 4, Wordpress looks to use page-4.php 5index.php Static page- aka “ Page Display Rules”
  19. 19. Post Pages Category Pages Tag Pages Custom Post Types Archive Pages Date Pages 3 1 2Author Pages
  20. 20. Category Pages Tag Pages Author Pages Date Pages 4 3 1 2 5 1 tag-{slug}.php tag-{id}.php tag.php archive.php index.php 4 3 2 5 1 category-{slug}.php category-{id}.php category.php archive.php index.php 4 3 2 5 1 author-{nicename}.php author-{id}.php author.php archive.php index.php 3 2 1 date.php archive.php index.php Custom Post Type Pages 3 2 1 archive-{post-type}.php archive.php index.php
  21. 21. Category Pages from Tag Pages Why learn this? Category from Category Differentiate Content Types 3 1 2 Category from Pages 4Pages
  22. 22. uestion? Qany
  23. 23. THANKS FOR YOUR ATTENTION Contact Website: onetarek.com Facebook.com/oneTarek Twitter.com/oneTarek WordPress : oneTarek Md Jahidul Islam(oneTarek)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×