WordPress | PHP - Hypertext Preprocessor
Standards Based Development
WordPress Codebase Notes
WordPress Documents
home.php
home.php is a template used for main page (on is_home()) condition.
index.php
index.php is universal template, it is what any page (home, archive, single post, etc) will use if no other template is available for it.
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.
Common Functions
get_header()- 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()- 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()- 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()- 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
Code Examples
The Loop aka Displaying Posts (have_posts())
<?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>
<>