This tutorial is for beginners who wants to code their own theme for the wordpress cms.It will give a basic outlook of the things needed for a wordpress template.For a detailed documentation refer – LINK . This tutorial contains the list of files and their purpose in the template and a sample wordpress template code for your understanding.
Template Files
style.css -The main stylesheet. This defines the style of the theme.
index.php- The main template.Which defines the layout.
comments.php -The comments template defined in the theme. If not present, comments.php from the “default” Theme is used.
home.php -The home page template.
single.php -The single post template. Used when a single post is queried. For this and all other query templates, index.php is used if the query template is not present.
page.php-The page template.
archive.php- The archive template. Note that this template will be overridden by category.php, author.php, and date.php for their respective query types.
search.php-The search results template. Used when a search is performed.
404.php-The 404 Not Found template. Used when WordPress cannot find a post or page that matches the query.
Functions to include in template
get_header()- It includes the header.php file content which is in the current theme. If that file is not found, it will instead include default header.php
get_footer()- TIt includes the footer.php file content which is in the current theme. If that file is not found, it will instead include default footer.php
get_sidebar() -It includes the sidebar.php file content which is in the current theme. If that file is not found, it will instead include default side bar.php
comments_template() -It includes the comments.php file content which is in the current theme. If that file
is not found, it will instead include default comments.php
Displaying Post’s
<?php
if (have_posts()) :
while (have_posts()) : // The Main Loop
the_post(); // Required Call
the_content(); // Get Content
endwhile ;
endif;
?>
Header.php
<!DOCTYPE html PUBLIC "-/ /W3 C/ /D TD XHTM L 1 .0 Transitio nal// EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> >
<head profile="http://gmpg.org/xfn/11">
<meta http -equiv="Content-Type" content=" <?php bloginfo( 'html_type' ); ?> ; c h a r s et= <?php
bloginfo(' charset '); ?> " / >
<title> <?php bloginfo(' name'); ?> <?php w p _ ti tl e ( ) ; ?> </title>
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url'); ?> " type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo( 'rss2_url' ); ?> " / >
<link rel="pingback" href=" <?php bloginfo( 'pingback_url' ); ?> " / >
<?php wp_get_archives('type=monthly&format=link' ) ; ?>
<?php comments_popup_script(); // off by default ?>
<?php wp_head(); // API Hook ?>
</head>
<body>
Sidebar.php
<ul>
<?php /* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar() ) : ?>
<li>
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
</li>
<?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>
<?php wp_list_bookmarks(); ?>
<li><h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</li>
<li><h2>Meta</h2>
<ul>
<?php w p_m eta() ; // API Hook ?>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?> < / l i >
</ul>
</li>
<?php endif; ?>
</ul>
Comments.php
<?php if ($comments) : ?>
<h3 id="comments"> <?php comments_number( 'No Responses', 'One Response', '% Responses' ); ?> to
<?php the_title(); ?> </ h3 >
<ol >
<?php foreach ($comments as $comment) : // The Comments Loop ?>
<li id="comment -<?php comment_ID() ?> ">
<?php echo g et_av atar( $ comment, 3 2 ); ?>
<cite><?php comment_author_link() ?> </ cite > Say s:
<?php if ($comment ->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<a href="#comment-<?php comment_ID() ?> " title="">
<?php comment_date('F jS, Y') ?> at <?php comment_time() ?>
< / a>
<?php comment_text() ?>
</li>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post ->comment_status) : // comments are open, but there are no comments ?>
<? php else : // comments are closed ?>
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
Footer.php
<?php wp_footer(); ?> </body> </html>

