word press templates

17
WordPress templates How the content you put into wp-admin gets turned into web pages

Upload: dan-phiffer

Post on 17-May-2015

1.073 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Word press templates

WordPress templatesHow the content you put into wp-admin gets

turned into web pages

Page 2: Word press templates

What are WordPress templates?

• Individual PHP files in a theme that you can modify

• Any given page request selects a particular template

• A child theme inherits (and overrides) the templates of its parent

Page 3: Word press templates

<?php

// Includes header.phpget_header();

// Content goes here

// Includes sidebar.phpget_sidebar();

// Includes footer.phpget_footer();

?>

A basic template

Page 4: Word press templates

<!DOCTYPE html><html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title><?php bloginfo('name'); ?></title> <?php wp_head(); ?> </head> <body>

header.php

Page 5: Word press templates

<?php wp_footer(); ?> </body></html>

footer.php

Page 6: Word press templates

<?php

// This is where helper functions and miscellaneous// theme settings go

// We can leave this empty for now

?>

functions.php

Page 7: Word press templates

<?php

// This can also be empty

?>

sidebar.php

Page 8: Word press templates

What kind of content?

• Group of posts

• Single post or page

• Media attachment

Page 9: Word press templates

Groups of posts

• Most recent posts (index.php)

• Posts in a specific category (category.php)

• Search results (search.php)

Page 10: Word press templates

The loop

The Loop is used by WordPress to display each of your posts. Using The Loop, WordPress processes each of the posts to be displayed on the current page and formats them according to how they match specified criteria within The Loop tags. Any HTML or PHP code placed in the Loop will be repeated on each post.”

—WordPress Codex

Page 11: Word press templates

<?php

while (have_posts()) { the_post(); // Display post content}

?>

A basic WordPress loop

Page 12: Word press templates

<?php

if (have_posts()) { while (have_posts()) { the_post(); // Display post content }} else { echo "Sorry, no posts were found.\n";}

?>

A more sophisticated loop, with error checking

Page 13: Word press templates

How do you display post content?

• Template Tags are pre-written helper functions you can use in your theme

• For example the_title() which prints out the current post’s title

• They are documented extensively

Page 14: Word press templates

<?php

while (have_posts() { the_post();

?><div id="<?php the_ID(); ?>"> <h1><?php the_title(); ?></h1> <div class="content"><?php the_content(); ?></div> Posted on <?php the_data(); ?> at <?php the_time(); ?></div><?php

}

?>

Using template tags

Page 15: Word press templates
Page 16: Word press templates
Page 17: Word press templates

Template hierarchy

index.php

header.php

footer.php

functions.php

home.php

front-page.php

404.php

search.php

archive.php

single.php

page.php

date.php

author.php

category.php

tag.php

taxonomy.php

attachment.php

custom.php