23
19 July 2013 WordPress Template Hierarchy Presented by haka WordPress Meetup 3 oneTarek.com Md Jahidul Islam(oneTarek)

Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

19 July 2013

WordPress Template Hierarchy

Presented by

Dhaka WordPress Meetup 3

oneTarek.comMd Jahidul Islam(oneTarek)

Page 2: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

The Question

How can I show different style and layout for different type pages like Home, Single,

Pages, Category, Tag, Taxonomy, Attachment etc.

Page 3: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 4: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

The Answer 2Easy and Best Way

WordPress loads different theme files

to display different types of pages

Page 5: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

The Question

What file(s) does WordPress use when it displays a certain type of page?

Page 6: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

The Answer?

Read Detail :

codex.wordpress.org/Template_Hierarchy

Template Hierarchy

Page 7: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Lets start with the basics

header.php

footer.php

sidebar.php

The Loop

Page 8: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

A working theme needs:

index.php + style.css =

A very basic but functional theme

Page 9: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

So what is with all of this then?

A: Different looks for different types of content

Page 10: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

home.php

Home Page Display Rules 12index.php

Page 11: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 12: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 13: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Single Post Page

Singular Page12Static page

Page 14: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Attachment post

Singlular page

Single post

3

12Custom Post

Blog post

Page 15: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 16: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 17: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

single-post.php

Singular Post single.php

Single Post- Blog Post

3

12

index.php

Page 18: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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”

Page 19: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Post Pages

Category PagesTag PagesCustom Post Types

Archive Pages

Date Pages3

1

2Author Pages

Page 20: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

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

Page 21: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

Category Pages from Tag Pages

Why learn this?Category from Category

Differentiate Content Types

3

12

Category from Pages

4 Pages

Page 22: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

uestion?Qany

Page 23: Dhaka WordPress Meetup 3 - Presentation for Template hierarchy

THANKSFOR YOUR ATTENTION

Contact

Website: onetarek.com

Facebook.com/oneTarek

Twitter.com/oneTarek

WordPress : oneTarek

Md Jahidul Islam(oneTarek)