Word press templates

1,177 views
1,143 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,177
On SlideShare
0
From Embeds
0
Number of Embeds
104
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Word press templates

  1. 1. WordPress templatesHow the content you put into wp-admin gets turned into web pages
  2. 2. What are WordPresstemplates?• 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
  3. 3. A basic template<?php// Includes header.phpget_header();// Content goes here// Includes sidebar.phpget_sidebar();// Includes footer.phpget_footer();?>
  4. 4. header.php<!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>
  5. 5. footer.php <?php wp_footer(); ?> </body></html>
  6. 6. functions.php<?php// This is where helper functions and miscellaneous// theme settings go// We can leave this empty for now?>
  7. 7. sidebar.php<?php// This can also be empty?>
  8. 8. What kind of content?• Group of posts• Single post or page• Media attachment
  9. 9. Groups of posts• Most recent posts (index.php)• Posts in a specific category (category.php)• Search results (search.php)
  10. 10. 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
  11. 11. A basic WordPress loop<?phpwhile (have_posts()) { the_post(); // Display post content}?>
  12. 12. A more sophisticated loop,with error checking<?phpif (have_posts()) { while (have_posts()) { the_post(); // Display post content }} else { echo "Sorry, no posts were found.n";}?>
  13. 13. How do you display postcontent?• 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
  14. 14. Using template tags<?phpwhile (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}?>
  15. 15. Template hierarchyindex.php home.php date.php front-page.php author.php 404.php category.phpheader.php search.php tag.phpfooter.php archive.php taxonomy.phpfunctions.php single.php attachment.php page.php custom.php

×