Tag Archives: single .php

SANGKRIT

Getting Started With WordPress Theme Development

A wordpress theme’s directory contains:

  1. index.php
  2. header.php
  3. footer.php
  4. single.php
  5. 404.php
  6. Search.php
  7. Page.php
  8. Comments.php
  9. Archive.php
  10. Tags.php
  11. Category.php
  12. Author.php
  13. siderbar.php
  14. function.php
  15. style.css

Before getting stared you may use these post links for getting familiar with the coding we are going to do here in the theme development:

(For example: Click on Function’s link to know, ‘How to create a function?’)

  1. Functions
  2. Loops
  3. If/Else Statements
  4. Arrays

Header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//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">

<title><?php

if ( is_single() ) { single_post_title(); }

elseif ( is_home() || is_front_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); get_page_number(); }

elseif ( is_page() ) { single_post_title(''); }

elseif ( is_search() ) { bloginfo('name'); print ' | Search results for ' . wp_specialchars($s); get_page_number(); }

elseif ( is_404() ) { bloginfo('name'); print ' | Not Found'; }

else { bloginfo('name'); wp_title('|'); get_page_number(); }

?></title>

<meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

<?php wp_head(); ?>

<link rel="alternate" type="application/rss+xml" href="<?php bloginfo('rss2_url'); ?>"title="<?php printf( __( '%s latest posts', 'your-theme' ), wp_specialchars( get_bloginfo('name'), 1 ) ); ?>" />

<link rel="alternate" type="application/rss+xml" href="<?php bloginfo('comments_rss2_url') ?>" title="<?php printf( __( '%s latest comments', 'your-theme' ), wp_specialchars( get_bloginfo('name'), 1 ) ); ?>" />

<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

</head>

<body>

<div id=”wrapper”>

<div id=”header”>

<div id=”masthead”>

<div id=”branding”>

<div id=”blog-title”><span><a href=”<?php bloginfo( ‘url’ ) ?>/” title=”<?php bloginfo( ‘name’ ) ?>” rel=”home”><?php bloginfo( ‘name’ ) ?></a></span></div>

<?php if ( is_home() || is_front_page() ) { ?>

<h1 id=”blog-description”><?php bloginfo( ‘description’ ) ?></h1>

<?php } else { ?>

<div id=”blog-description”><?php bloginfo( ‘description’ ) ?></div>

<?php } ?>

</div><!– #branding –>

 

<div id=”access”>

<div><a href=”#content” title=”<?php _e( ‘Skip to content’, ‘your-theme’ ) ?>”><?php _e( ‘Skip to content’, ‘your-theme’ ) ?></a></div>

<?php wp_page_menu( ‘sort_column=menu_order’ ); ?>

</div> <!– #access –>

 

</div><!– #masthead –>

</div><!– #header –>

 

<div id=”main”>

 

Description:

Code block in red and orange color at the top of header.php tells the document type which helps the browser to interpret the HTML seeing. While the orange lines of code add few attributes that makes the page apparent to the web browser.

Code block in green color, you must be remembering simple <head></head> HTML tags. This is a quite similar but here it is looks like a complex block of code because the code in between <title> and </title> is basically for the search engine result.

The code line starting from <meta http gives concise information about your website and the code line starting from <link rel “stylesheet” is used for linking the stylesheet. Other <link rel code lines specify the feeds basically RSS and other pingbacks  <?php wp_head(); ?> is a catch for the plugins etc. Other code includes thread for the comments etc which you may easily understand by reading the code carefully and if you face any problem then send me an e-mail.

The code in purple color, is a code block of conditional wordpress tags for coding title and blog description, this will be helpful for the branding of your site as it will send your blog title in search engines.

Code block in light green color, here we have added a skip link so as to make a screen reader can easily get specific content, helpful for the persons using a screen reader. Other than this we have added our page menu. Just read the code carefully and you will understand everything.

 

Footer.php

</div><!– #main –>

 

<div id=”footer”>

<div id=”colophon”>

 

<div id=”site-info”>

</div><!– #site-info –>

 

</div><!– #colophon –>

</div><!– #footer –>

</div><!– #wrapper –>

</body>

</html>

 

Index.php

As you have made header.php and footer.php files earlier, so now you need to call them to index.php. Now we will be calling header.php file by adding the following line of code at the top of your index.php file:

<?php get_header(); ?>

Now at the very bottom of your index.php file, call footer.php file as it follows:

<?php get_footer(); ?>

Before footer.php you also have to call sidebar.ph by following command:

<?php get_sidebar(); ?>

Main Index.php will look like:

<?php get_header(); ?>

<div id=”container”>

 

<div id=”content”>

<?php /* Top post navigation */ ?>

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php /* The Loop — having comments */ ?>

<?php while ( have_posts() ) : the_post() ?>

 

<div id=”post-<?php the_ID(); ?>”

<?php post_class(); ?>>

<?php /* an h2 title */ ?>

 

<?php /*Following code between <h2 class to </h2>  is a template tag to get the title of the post and wrap in  tag that links to permalink which is a permalink to a specific post and we had added another title attribute which will help search engines to get permalink to a post*/ ?>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

 

<?php /* Microformatted, translatable post meta */ ?>

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<?php /* The entry content, will make machines know that this is blog post content */ ?>

 

<div class=”entry-content”>

<?php the_content( __( ‘Continue reading <span class=”meta-nav”>&raquo;</span>’, ‘your-theme’ )  ); ?>

<?php wp_link_pages(‘before=<div>’ . __( ‘Pages:’, ‘your-theme’ ) . ‘&after=</div>’) ?>

</div><!– .entry-content –>

 

<?php /* Microformatted category and tag links along with a comments link */ ?>

<div class=”entry-utility”>

<span class=”cat-links”><span><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php /* Close up the post div and then end the loop with endwhile */ ?>

 

<?php endwhile; ?>

 

<?php /* Bottom post navigation */ ?>

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

 

</div><!– #content –>

 

</div><!– #container –>

 

<div id=”primary”>

</div><!– #primary .widget-area –>

 

<div id=”secondary”>

</div><!– #secondary –>

 

<?php get_sidebar(); ?>

 

<?php get_footer(); ?>

Code block in dark blue color represents the content. Everything is explained by giving black color comments in between coding of index.php file.

Two code blocks in red color having comments ‘Top post navigation’ and ‘Bottom post navigation’ just before and after the dark blue color loop code represents the navigation which helps us to navigate away from the posts. Tag: next_posts_link()creates  link to previous posts while the tag: previous_posts_link()creates a link for next post so don’t get confused with their names as they are having opposite meaning.

Functions.php

<?php

//Function for Theme available for translation

// Translations can be done in /languages/ directory

load_theme_textdomain( ‘your-theme’, TEMPLATEPATH . ‘/languages’ );

 

$locale = get_locale();

$locale_file = TEMPLATEPATH . “/languages/$locale.php”;

if ( is_readable($locale_file) )

require_once($locale_file);

 

//Function for getting page number

function get_page_number() {

if ( get_query_var(‘paged’) ) {

print ‘ | ‘ . __( ‘Page ‘ , ‘your-theme’) . get_query_var(‘paged’);

}

} // end get_page_number

 

Read the above given code carefully, the first function is for the getting page’s translation and the second function is for getting page numbers.

 

Now create a template for single.php as shown below. Its temple is same as index.php. You have to call header.php, footer.php, sidebar.php same as we have done in index.php.

Single.php

<?php get_header(); ?>

 

<div id=”container”>

<div id=”content”>

<?php /*single post navigation*/ ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php previous_post_link( ‘%link’, ‘<span>&laquo;</span> %title’ ) ?></div>

<div class=”nav-next”><?php next_post_link( ‘%link’, ‘%title <span>&raquo;</span>’ ) ?></div>

</div><!– #nav-above –>

 

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<?php /*single post titles for the eyes of screen readers, likewise we have done the same in header.php earlier*/ ?>

<h1 class="entry-title"><?php the_title(); ?></h1>

 

<?php /*function call followed by wp_link_pages().*/?>

 

<?php the_content(); ?>

<?php wp_link_pages(‘before=<div>’ . __( ‘Pages:’, ‘your-theme’ ) . ‘&after=</div>’) ?>

 

 

 

<?php /*Links for single post entry*/?>

<div>

<?php printf( __( ‘This entry was posted in %1$s%2$s. Bookmark the <a href=”%3$s” title=”Permalink to %4$s” rel=”bookmark”>permalink</a>. Follow any comments here with the <a href=”%5$s” title=”Comments RSS to %4$s” rel=”alternate” type=”application/rss+xml”>RSS feed for this post</a>.’, ‘your-theme’ ),

get_the_category_list(‘, ‘),

get_the_tag_list( __( ‘ and tagged ‘, ‘your-theme’ ), ‘, ‘, ” ),

get_permalink(),

the_title_attribute(‘echo=0′),

comments_rss() ) ?>

 

<?php if ( (‘open’ == $post->comment_status) && (‘open’ == $post->ping_status) ) : // Comments and trackbacks open ?>

<?php printf( __( ‘<a href=”#respond” title=”Post a comment”>Post a comment</a> or leave a trackback: <a href=”%s” title=”Trackback URL for your post” rel=”trackback”>Trackback URL</a>.’, ‘your-theme’ ), get_trackback_url() ) ?>

<?php elseif ( !(‘open’ == $post->comment_status) && (‘open’ == $post->ping_status) ) : // Only trackbacks open ?>

<?php printf( __( ‘Comments are closed, but you can leave a trackback: <a class=”trackback-link” href=”%s” title=”Trackback URL for your post” rel=”trackback”>Trackback URL</a>.’, ‘your-theme’ ), get_trackback_url() ) ?>

<?php elseif ( (‘open’ == $post->comment_status) && !(‘open’ == $post->ping_status) ) : // Only comments open ?>

<?php _e( ‘Trackbacks are closed, but you can <a href=”#respond” title=”Post a comment”>post a comment</a>.’, ‘your-theme’ ) ?>

<?php elseif ( !(‘open’ == $post->comment_status) && !(‘open’ == $post->ping_status) ) : // Comments and trackbacks closed ?>

<?php _e( ‘Both comments and trackbacks are currently closed.’, ‘your-theme’ ) ?>

<?php endif; ?>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “nttttt<span class=”edit-link”>”, “</span>” ) ?>

</div><!– .entry-utility –>

 

 

 

</div><!– #post-<?php the_ID(); ?> –>

 

 

 

<?php /*single post navigation*/ ?>

 

<div id=”nav-below”>

<div class=”nav-previous”><?php previous_post_link( ‘%link’, ‘<span>&laquo;</span> %title’ ) ?></div>

<div class=”nav-next”><?php next_post_link( ‘%link’, ‘%title <span>&raquo;</span>’ ) ?></div>

</div><!– #nav-below –>

 

<?php /*Likewise it is a single post template hence we will need to call           comments_template() we will be coding up comments.php further*/ ?>

<?php comments_template('', true); ?>

 

</div><!– #content –>

</div><!– #container –>

 

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Code block in red color, under the comment heading ‘links for single post entry’ is a bit complicated code block because of the style of working of wordpress comments likewise for opening comments and trackbacks, for opening only comments and keeping trackbacks closed.

Post Attachment (attachment.php)

Easiest way to created attachment.php is to copy single.php, renaming it to attachment.php and doing the following changes:

First delete the top and bottom navigation, it is not needed anymore. Replace it with a page title that links back to parent post, as shown:

<h1><a href="<?php echo get_permalink($post->post_parent) ?>" title="<?php printf( __( 'Return to %s', 'your-theme' ), wp_specialchars( get_the_title($post->post_parent), 1 ) ) ?>" rev="attachment"><span class="meta-nav">&laquo; </span><?php echo get_the_title($post->post_parent) ?></a></h1>

Likewise page title is in h1 tag hence we will be wrapping our post title in h2 tag.

<h2><?php the_title(); ?></h2>

 

Attachment.php actually shows the attachments hence our content should reflect that.

<div>

<div class=”entry-attachment”>

<?php if ( wp_attachment_is_image( $post->id ) ) : $att_image = wp_get_attachment_image_src( $post->id, “medium”); ?>

<p class=”attachment”><a href=”<?php echo wp_get_attachment_url($post->id); ?>” title=”<?php the_title(); ?>” rel=”attachment”><img src=”<?php echo $att_image[0];?>” width=”<?php echo $att_image[1];?>” height=”<?php echo $att_image[2];?>”  alt=”<?php $post->post_excerpt; ?>” /></a>

</p>

<?php else : ?>

<a href=”<?php echo wp_get_attachment_url($post->ID) ?>” title=”<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>” rel=”attachment”><?php echo basename($post->guid) ?></a>

<?php endif; ?>

</div>

<div class=”entry-caption”><?php if ( !empty($post->post_excerpt) ) the_excerpt() ?></div>

 

<?php the_content( __( ‘Continue reading <span class=”meta-nav”>&raquo;</span>’, ‘your-theme’ )  ); ?>

<?php wp_link_pages(‘before=<div>’ . __( ‘Pages:’, ‘your-theme’ ) . ‘&after=</div>’) ?>

 

</div><!– .entry-content –>

 

404 template (404.php)

It will work when someone types the wrong URL of your blog. It is an error server code.

<?php get_header(); ?>

 

<div id=”container”>

<div id=”content”>

 

<div id=”post-0″>

<h1 class=”entry-title”><?php _e( ‘Not Found’, ‘your-theme’ ); ?></h1>

<div class=”entry-content”>

<p><?php _e( ‘Sorry, unable to find particular page.’, ‘your-theme’ ); ?></p>

<?php get_search_form(); ?>

</div><!– .entry-content –>

</div><!– #post-0 –>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

</div><!– #post-<?php the_ID(); ?> –>

 

 

</div><!– #content –>

</div><!– #container –>

 

<?php get_sidebar(); ?>

<?php get_footer(); ?>

 

Comments Template (comments.php)

Add the following two functions to your functions.php file for callback of your comments and trackbacks:

First function for your function.php file:

//Callback to list comments in theme 

function custom_comments($comment, $args, $depth) {

$GLOBALS['comment'] = $comment;

$GLOBALS['comment_depth'] = $depth;

?>

<li id=”comment-<?php comment_ID() ?>” <?php comment_class() ?>>

<div ><?php commenter_link() ?></div>

<div ><?php printf(__(‘Posted %1$s at %2$s <span>|</span> <a href=”%3$s” title=”Permalink to this comment”>Permalink</a>’, ‘your-theme’),

get_comment_date(),

get_comment_time(),

‘#comment-’ . get_comment_ID() );

edit_comment_link(__(‘Edit’, ‘your-theme’), ‘ <span>|</span> <span>’, ‘</span>’); ?></div>

<?php if ($comment->comment_approved == ’0′) _e(“ttttt<span class=’unapproved’>Your comment is awaiting moderation.</span>n”, ‘your-theme’) ?>

<div >

<?php comment_text() ?>

</div>

<?php // echo the comment reply link

if($args['type'] == ‘all’ || get_comment_type() == ‘comment’) :

comment_reply_link(array_merge($args, array(

‘reply_text’ => __(‘Reply’,’your-theme’),

‘login_text’ => __(‘Log in to reply.’,’your-theme’),

‘depth’ => $depth,

‘before’ => ‘<div >’,

‘after’ => ‘</div>’

)));

endif;

?>

<?php } // end custom_comments

 

 

Second function for your function.php file:

// Callback to list pings 

function custom_pings($comment, $args, $depth) {

$GLOBALS['comment'] = $comment;

?>

<li id=”comment-<?php comment_ID() ?>” <?php comment_class() ?>>

<div ><?php printf(__(‘By %1$s on %2$s at %3$s’, ‘your-theme’),

get_comment_author_link(),

get_comment_date(),

get_comment_time() );

edit_comment_link(__(‘Edit’, ‘your-theme’), ‘ <span>|</span> <span>’, ‘</span>’); ?></div>

<?php if ($comment->comment_approved == ’0′) _e(‘ttttt<span>Your trackback is awaiting moderation.</span>n’, ‘your-theme’) ?>

<div >

<?php comment_text() ?>

</div>

<?php } // end custom_pings

 

 

Also add the following function to your function.php file for showing gravatar in the comments:

// For producing avatar image with the hCard-compliant photo class 

function commenter_link() {

$commenter = get_comment_author_link();

if ( ereg( ‘<a[^>]* class=[^>]+>’, $commenter ) ) {

$commenter = ereg_replace( ‘(<a[^>]* class=['"]?)’, ’1url ‘ , $commenter );

} else {

$commenter = ereg_replace( ‘(<a )/’, ’1class=”url “‘ , $commenter );

}

$avatar_email = get_comment_author_email();

$avatar = str_replace( “class=’avatar”, “class=’photo avatar”, get_avatar( $avatar_email, 80 ) );

echo $avatar . ‘ <span>’ . $commenter . ‘</span>’;

} // end commenter_link

 

 

Now we have added all the important functions to functions.php file. Hence this is the time to create comments template i.e. comments.php file:

comments.php

<?php /* The Comments Template — with, er, comments! */ ?>

<div id=”comments”>

<?php /* Run some checks for bots and password protected posts */ ?>

<?php

$req = get_option(‘require_name_email’); // Checks if fields are required.

if ( ‘comments.php’ == basename($_SERVER['SCRIPT_FILENAME']) )

die ( ‘Please do not load this page directly. Thanks!’ );

if ( ! empty($post->post_password) ) :

if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :

?>

<div class=”nopassword”><?php _e(‘This post is password protected. Enter the password to view any comments.’, ‘your-theme’) ?></div>

</div><!– .comments –>

<?php

return;

endif;

endif;

?>

 

<?php /* See IF there are comments and do the comments stuff! */ ?>

<?php if ( have_comments() ) : ?>

 

<?php /* Count the number of comments and trackbacks (or pings) */

$ping_count = $comment_count = 0;

foreach ( $comments as $comment )

get_comment_type() == “comment” ? ++$comment_count : ++$ping_count;

?>

 

<?php /* IF there are comments, show the comments */ ?>

<?php if ( ! empty($comments_by_type['comment']) ) : ?>

 

<div id=”comments-list”>

<h3><?php printf($comment_count > 1 ? __(‘<span>%d</span> Comments’, ‘your-theme’) : __(‘<span>One</span> Comment’, ‘your-theme’), $comment_count) ?></h3>

 

<?php /* If there are enough comments, build the comment navigation  */ ?>

<?php $total_pages = get_comment_pages_count(); if ( $total_pages > 1 ) : ?>

<div id=”comments-nav-above”>

<div class=”paginated-comments-links”><?php paginate_comments_links(); ?></div>

</div><!– #comments-nav-above –>

<?php endif; ?>

 

<?php /* An ordered list of our custom comments callback, custom_comments(), in functions.php   */ ?>

<ol>

<?php wp_list_comments(‘type=comment&callback=custom_comments’); ?>

</ol>

 

<?php /* If there are enough comments, build the comment navigation */ ?>

<?php $total_pages = get_comment_pages_count(); if ( $total_pages > 1 ) : ?>

<div id=”comments-nav-below”>

<div class=”paginated-comments-links”><?php paginate_comments_links(); ?></div>

</div><!– #comments-nav-below –>

<?php endif; ?>

 

</div><!– #comments-list .comments –>

 

<?php endif; /* if ( $comment_count ) */ ?>

 

<?php /* If there are trackbacks(pings), show the trackbacks  */ ?>

<?php if ( ! empty($comments_by_type['pings']) ) : ?>

 

<div id=”trackbacks-list”>

<h3><?php printf($ping_count > 1 ? __(‘<span>%d</span> Trackbacks’, ‘your-theme’) : __(‘<span>One</span> Trackback’, ‘your-theme’), $ping_count) ?></h3>

 

<?php /* An ordered list of our custom trackbacks callback, custom_pings(), in functions.php   */ ?>

<ol>

<?php wp_list_comments(‘type=pings&callback=custom_pings’); ?>

</ol>

 

</div><!– #trackbacks-list .comments –>

 

<?php endif /* if ( $ping_count ) */ ?>

<?php endif /* if ( $comments ) */ ?>

 

<?php /* If comments are open, build the respond form */ ?>

<?php if ( ‘open’ == $post->comment_status ) : ?>

<div id=”respond”>

<h3><?php comment_form_title( __(‘Post a Comment’, ‘your-theme’), __(‘Post a Reply to %s’, ‘your-theme’) ); ?></h3>

 

<div id=”cancel-comment-reply”><?php cancel_comment_reply_link() ?></div>

 

<?php if ( get_option(‘comment_registration’) && !$user_ID ) : ?>

<p id=”login-req”><?php printf(__(‘You must be <a href=”%s” title=”Log in”>logged in</a> to post a comment.’, ‘your-theme’),

get_option(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . get_permalink() ) ?></p>

 

<?php else : ?>

<div class=”formcontainer”>

 

<form id=”commentform” action=”<?php echo get_option(‘siteurl’); ?>/wp-comments-post.php” method=”post”>

 

<?php if ( $user_ID ) : ?>

<p id=”login”><?php printf(__(‘<span>Logged in as <a href=”%1$s” title=”Logged in as %2$s”>%2$s</a>.</span> <span class=”logout”><a href=”%3$s” title=”Log out of this account”>Log out?</a></span>’, ‘your-theme’),

get_option(‘siteurl’) . ‘/wp-admin/profile.php’,

wp_specialchars($user_identity, true),

wp_logout_url(get_permalink()) ) ?></p>

 

<?php else : ?>

 

<p id=”comment-notes”><?php _e(‘Your email is <em>never</em> published nor shared.’, ‘your-theme’) ?> <?php if ($req) _e(‘Required fields are marked <span class=”required”>*</span>’, ‘your-theme’) ?></p>

 

<div id=”form-section-author”>

<div class=”form-label”><label for=”author”><?php _e(‘Name’, ‘your-theme’) ?></label> <?php if ($req) _e(‘<span class=”required”>*</span>’, ‘your-theme’) ?></div>

<div class=”form-input”><input id=”author” name=”author” type=”text” value=”<?php echo $comment_author ?>” size=”30″ maxlength=”20″ tabindex=”3″ /></div>

</div><!– #form-section-author .form-section –>

 

<div id=”form-section-email”>

<div class=”form-label”><label for=”email”><?php _e(‘Email’, ‘your-theme’) ?></label> <?php if ($req) _e(‘<span class=”required”>*</span>’, ‘your-theme’) ?></div>

<div class=”form-input”><input id=”email” name=”email” type=”text” value=”<?php echo $comment_author_email ?>” size=”30″ maxlength=”50″ tabindex=”4″ /></div>

</div><!– #form-section-email .form-section –>

 

<div id=”form-section-url”>

<div class=”form-label”><label for=”url”><?php _e(‘Website’, ‘your-theme’) ?></label></div>

<div class=”form-input”><input id=”url” name=”url” type=”text” value=”<?php echo $comment_author_url ?>” size=”30″ maxlength=”50″ tabindex=”5″ /></div>

</div><!– #form-section-url .form-section –>

 

<?php endif /* if ( $user_ID ) */ ?>

 

<div id=”form-section-comment”>

<div class=”form-label”><label for=”comment”><?php _e(‘Comment’, ‘your-theme’) ?></label></div>

<div class=”form-textarea”><textarea id=”comment” name=”comment” cols=”45″ rows=”8″ tabindex=”6″></textarea></div>

</div><!– #form-section-comment .form-section –>

 

<div id=”form-allowed-tags”>

<p><span><?php _e(‘You may use these <abbr title=”HyperText Markup Language”>HTML</abbr> tags and attributes:’, ‘your-theme’) ?></span> <code><?php echo allowed_tags(); ?></code></p>

</div>

 

<?php do_action(‘comment_form’, $post->ID); ?>

 

<div class=”form-submit”><input id=”submit” name=”submit” type=”submit” value=”<?php _e(‘Post Comment’, ‘your-theme’) ?>” tabindex=”7″ /><input type=”hidden” name=”comment_post_ID” value=”<?php echo $id; ?>” /></div>

 

<?php comment_id_fields(); ?>

 

<?php /* Just … end everything. We’re done here. Close it up. */ ?>

 

</form><!– #commentform –>

</div><!– .formcontainer –>

<?php endif /* if ( get_option(‘comment_registration’) && !$user_ID ) */ ?>

</div><!– #respond –>

<?php endif /* if ( ‘open’ == $post->comment_status ) */ ?>

</div><!– #comments –>

 

Now it’s all done, your comments.php template is ready. Read the code and description of three functions given at the top and the code of comments.php carefully.

Search Template (search.php)

This is the search result template used when a search is performed.

The code is almost same to the single.php template, we will be writing some code under the bold remark given in the file here:

<?php get_header(); ?>

 

<div id=”container”>

<div id=”content”>

 

<?php if ( have_posts() ) : ?>

 

<?php while ( have_posts() ) : the_post() ?>

<!– this is our loop –>

<?php endwhile; ?>

 

<?php else : ?>

 

<!– here’s we’ll put a search form if there’re no posts –>

 

<?php endif; ?>

 

</div><!– #content –>

</div><!– #container –>

 

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Code if you like to check that if you are dealing with post or page:

<?php if ( $post->post_type == ‘post’ ) { ?>

<?php } ?>

 

The #content div of search template will be:

<?php if ( have_posts() ) : ?>

 

<h1 class=”page-title”><?php _e( ‘Search Results for: ‘, ‘your-theme’ ); ?><span><?php the_search_query(); ?></span></h1>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post() ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<?php if ( $post->post_type == ‘post’ ) { ?>

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

<?php } ?>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

<?php wp_link_pages(‘before=<div>’ . __( ‘Pages:’, ‘your-theme’ ) . ‘&after=</div>’) ?>

</div><!– .entry-summary –>

 

<?php if ( $post->post_type == ‘post’ ) { ?>

<div class=”entry-utility”>

<span class=”cat-links”><span><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

<?php } ?>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

<?php else : ?>

 

<div id=”post-0″>

<h2 class=”entry-title”><?php _e( ‘Nothing Found’, ‘your-theme’ ) ?></h2>

<div class=”entry-content”>

<p><?php _e( ‘Sorry, but nothing matched your search criteria. Please try again with some different keywords.’, ‘your-theme’ ); ?></p>

<?php get_search_form(); ?>

</div><!– .entry-content –>

</div>

 

<?php endif; ?>

 

Page Template (page.php)

Same block of code as we have seen earlier but we are adding a little difference as this template is of a particular page, likewise if we usually create different pages in our blog.

Page template is used when an individual page is queried.

Here is the code page.php:

<?php get_header(); ?>

 

<div id=”container”>

<div id=”content”>

 

<?php the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h1 class=”entry-title”><?php the_title(); ?></h1>

<div class=”entry-content”>

<?php the_content(); ?>

<?php wp_link_pages(‘before=<div class=”page-link”>’ . __( ‘Pages:’, ‘your-theme’ ) . ‘&after=</div>’) ?>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), ‘<span>’, ‘</span>’ ) ?>

</div><!– .entry-content –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php if ( get_post_custom_values(‘comments’) ) comments_template() // Add a custom field with Name and Value of “comments” to enable comments on this page ?>

 

</div><!– #content –>

</div><!– #container –>

 

<?php get_sidebar(); ?>

<?php get_footer(); ?>

 

Archive Template (archive.php)

An important template. It shows posts on a certain criteria (you must have seen blog posts on the sidebar listed according to dates.

Here is your archive.php template containing loops same kind of loops which we have discussed earlier. The templates calls the posts rewind them etc.

<?php the_post(); ?>

 

<?php if ( is_day() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Daily Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(get_option(‘date_format’)) ) ?></h1>

<?php elseif ( is_month() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Monthly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘F Y’) ) ?></h1>

<?php elseif ( is_year() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Yearly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘Y’) ) ?></h1>

<?php elseif ( isset($_GET['paged']) && !empty($_GET['paged']) ) : ?>

<h1 class=”page-title”><?php _e( ‘Blog Archives’, ‘your-theme’ ) ?></h1>

<?php endif; ?>

 

<?php rewind_posts(); ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

</div><!– .entry-summary –>

 

<div class=”entry-utility”>

<span class=”cat-links”><span><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

Author Template (author.php)

This is a quite easy to create. Following is the same author.php template but the red color code block is to be replaced by the code given after the following template which is basically the title section:

<?php the_post(); ?>

 

<?php if ( is_day() ) : ?>

<h1><?php printf( __( ‘Daily Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(get_option(‘date_format’)) ) ?></h1>

<?php elseif ( is_month() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Monthly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘F Y’) ) ?></h1>

<?php elseif ( is_year() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Yearly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘Y’) ) ?></h1>

<?php elseif ( isset($_GET['paged']) && !empty($_GET['paged']) ) : ?>

<h1 class=”page-title”><?php _e( ‘Blog Archives’, ‘your-theme’ ) ?></h1>

<?php endif; ?>

 

<?php rewind_posts(); ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

</div><!– .entry-summary –>

 

<div class=”entry-utility”>

<span class=”cat-links”><span><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

Put the following code in the above given archive.php template’s red title section and save the template as author.php:

<h1 class=”page-title author”><?php printf( __( ‘Author Archives: <span>%s</span>’, ‘your-theme’ ), “<a class=’url fn n’ href=’$authordata->user_url’ title=’$authordata->display_name’ rel=’me’>$authordata->display_name</a>” ) ?></h1>

<?php $authordesc = $authordata->user_description; if ( !empty($authordesc) ) echo apply_filters( ‘archive_meta’, ‘<div>’ . $authordesc . ‘</div>’ ); ?>

 

Category Template (category.php)

Make a copy of archive.php template and save it as category.php. Then put the following given function in function.php:

// For category lists: Returns other categories except the current category

function cats_meow($glue) {

$current_cat = single_cat_title( ”, false );

$separator = “n”;

$cats = explode( $separator, get_the_category_list($separator) );

foreach ( $cats as $i => $str ) {

if ( strstr( $str, “>$current_cat<” ) ) {

unset($cats[$i]);

break;

}

}

if ( empty($cats) )

return false;

 

return trim(join( $glue, $cats ));

} // end cats_meow

 

Now in the category.php which you have copied from archive.php, replace the title section that old one of red color with the following given code:

<h1 class=”page-title”><?php _e( ‘Category Archives:’, ‘your-theme’ ) ?> <span><?php single_cat_title() ?></span></span></h1>

<?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( ‘archive_meta’, ‘<div>’ . $categorydesc . ‘</div>’ ); ?>

 

Your category.php would be looking like this:

<?php the_post(); ?>

 

<?php if ( is_day() ) : ?>

<h1 class=”page-title”><?php _e( ‘Category Archives:’, ‘your-theme’ ) ?> <span><?php single_cat_title() ?></span></span></h1>

<?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( ‘archive_meta’, ‘<div>’ . $categorydesc . ‘</div>’ ); ?>

<?php endif; ?>

 

<?php rewind_posts(); ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

</div><!– .entry-summary –>

 

<div class=”entry-utility”>

<span><span class=”entry-utility-prep entry-utility-prep-cat-links”><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

Now replace the blue color code block in #entry-utility with the following code:

<?php if ( $cats_meow = cats_meow(‘, ‘) ) : // Returns categories other than the one queried ?>

<span class=”cat-links”><?php printf( __( ‘Also posted in %s’, ‘your-theme’ ), $cats_meow ) ?></span>

<span class=”meta-sep”> | </span>

<?php endif ?>

Hence, the final look of your category.php is:

<?php the_post(); ?>

 

<?php if ( is_day() ) : ?>

<h1 class=”page-title”><?php _e( ‘Category Archives:’, ‘your-theme’ ) ?> <span><?php single_cat_title() ?></span></span></h1>

<?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( ‘archive_meta’, ‘<div>’ . $categorydesc . ‘</div>’ ); ?>

<?php endif; ?>

 

<?php rewind_posts(); ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

</div><!– .entry-summary –>

 

<div>

<?php if ( $cats_meow = cats_meow(‘, ‘) ) : // Returns categories other than the one queried ?>

<span class=”cat-links”><?php printf( __( ‘Also posted in %s’, ‘your-theme’ ), $cats_meow ) ?></span>

<span class=”meta-sep”> | </span>

<?php endif ?>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span><span class=”entry-utility-prep entry-utility-prep-tag-links”>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

Tags Template (tags.php)

As clear from name; the template is about tags. Again create another copy of archive.php and rename it to tags.php and then drop following function to functions.php:

// lists tag on tag archives: Returns other tags except the current

function tag_ur_it($glue) {

$current_tag = single_tag_title( ”, ”,  false );

$separator = “n”;

$tags = explode( $separator, get_the_tag_list( “”, “$separator”, “” ) );

foreach ( $tags as $i => $str ) {

if ( strstr( $str, “>$current_tag<” ) ) {

unset($tags[$i]);

break;

}

}

if ( empty($tags) )

return false;

 

return trim(join( $glue, $tags ));

} // end tag_ur_it

 

Following is your renamed copy of archive.php template. Do the changes given after this template:
<?php the_post(); ?>

 

<?php if ( is_day() ) : ?>

<h1><?php printf( __( ‘Daily Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(get_option(‘date_format’)) ) ?></h1>

<?php elseif ( is_month() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Monthly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘F Y’) ) ?></h1>

<?php elseif ( is_year() ) : ?>

<h1 class=”page-title”><?php printf( __( ‘Yearly Archives: <span>%s</span>’, ‘your-theme’ ), get_the_time(‘Y’) ) ?></h1>

<?php elseif ( isset($_GET['paged']) && !empty($_GET['paged']) ) : ?>

<h1 class=”page-title”><?php _e( ‘Blog Archives’, ‘your-theme’ ) ?></h1>

<?php endif; ?>

 

<?php rewind_posts(); ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-above”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-above –>

<?php } ?>

 

<?php while ( have_posts() ) : the_post(); ?>

 

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

<h2 class=”entry-title”><a href=”<?php the_permalink(); ?>” title=”<?php printf( __(‘Permalink to %s’, ‘your-theme’), the_title_attribute(‘echo=0′) ); ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

 

<div class=”entry-meta”>

<span class=”meta-prep meta-prep-author”><?php _e(‘By ‘, ‘your-theme’); ?></span>

<span class=”author vcard”><a href=”<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>” title=”<?php printf( __( ‘View all posts by %s’, ‘your-theme’ ), $authordata->display_name ); ?>”><?php the_author(); ?></a></span>

<span class=”meta-sep”> | </span>

<span class=”meta-prep meta-prep-entry-date”><?php _e(‘Published ‘, ‘your-theme’); ?></span>

<span class=”entry-date”><abbr title=”<?php the_time(‘Y-m-dTH:i:sO’) ?>”><?php the_time( get_option( ‘date_format’ ) ); ?></abbr></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>nttttt” ) ?>

</div><!– .entry-meta –>

 

<div class=”entry-summary”>

<?php the_excerpt( __( ‘Continue reading <span>&raquo;</span>’, ‘your-theme’ )  ); ?>

</div><!– .entry-summary –>

 

<div class=”entry-utility”>

<span class=”cat-links”><span><?php _e( ‘Posted in ‘, ‘your-theme’ ); ?></span><?php echo get_the_category_list(‘, ‘); ?></span>

<span class=”meta-sep”> | </span>

<?php the_tags( ‘<span class=”tag-links”><span>’ . __(‘Tagged ‘, ‘your-theme’ ) . ‘</span>’, “, “, “</span>ntttttt<span class=”meta-sep”>|</span>n” ) ?>

<span class=”comments-link”><?php comments_popup_link( __( ‘Leave a comment’, ‘your-theme’ ), __( ’1 Comment’, ‘your-theme’ ), __( ‘% Comments’, ‘your-theme’ ) ) ?></span>

<?php edit_post_link( __( ‘Edit’, ‘your-theme’ ), “<span class=”meta-sep”>|</span>ntttttt<span class=”edit-link”>”, “</span>ntttttn” ) ?>

</div><!– #entry-utility –>

</div><!– #post-<?php the_ID(); ?> –>

 

<?php endwhile; ?>

 

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>

<div id=”nav-below”>

<div class=”nav-previous”><?php next_posts_link(__( ‘<span class=”meta-nav”>&laquo;</span> Older posts’, ‘your-theme’ )) ?></div>

<div class=”nav-next”><?php previous_posts_link(__( ‘Newer posts <span>&raquo;</span>’, ‘your-theme’ )) ?></div>

</div><!– #nav-below –>

<?php } ?>

 

Replace red color code block of tite with:

<h1 class="page-title"><?php _e( 'Tag Archives:', 'your-theme' ) ?> <span><?php single_tag_title() ?></span></h1>

And, replace the blue color code block of entry-utility with:

<?php if ( $tag_ur_it = tag_ur_it(‘, ‘) ) : // Returns tags other than the one queried ?>

<span class=”tag-links”><?php printf( __( ‘Also tagged %s’, ‘your-theme’ ), $tag_ur_it ) ?></span>

<?php endif; ?>

 

Now, the following is your complete template of tags.php

Sidebar Template (sidebar.php)

Register widget areas in functions.php for your sidebar by the following code block:

// Registering widget areas

function theme_widgets_init() {

// Area 1

register_sidebar( array (

‘name’ => ‘Primary Widget Area’,

‘id’ => ‘primary_widget_area’,

‘before_widget’ => ‘<li id=”%1$s” class=”widget-container %2$s”>’,

‘after_widget’ => “</li>”,

‘before_title’ => ‘<h3>’,

‘after_title’ => ‘</h3>’,

) );

 

// Area 2

register_sidebar( array (

‘name’ => ‘Secondary Widget Area’,

‘id’ => ‘secondary_widget_area’,

‘before_widget’ => ‘<li id=”%1$s” class=”widget-container %2$s”>’,

‘after_widget’ => “</li>”,

‘before_title’ => ‘<h3>’,

‘after_title’ => ‘</h3>’,

) );

} // end theme_widgets_init

 

add_action( ‘init’, ‘theme_widgets_init’ );

Drop following function in function.php to check for widgets in the widget areas:

function is_sidebar_active( $index ){

global $wp_registered_sidebars;

 

$widgetcolums = wp_get_sidebars_widgets();

 

if ($widgetcolums[$index]) return true;

 

return false;

}

 

Add the following code in functions.php for the wordpress to add default widgets:

 

$preset_widgets = array (

‘primary_widget_area’  => array( ‘search’, ‘pages’, ‘categories’, ‘archives’ ),

‘secondary_widget_area’  => array( ‘links’, ‘meta’ )

);

if ( isset( $_GET['activated'] ) ) {

update_option( ‘sidebars_widgets’, $preset_widgets );

}

 

Now last step is to create your sidebar.php template:

<?php if ( is_sidebar_active(‘primary_widget_area’) ) : ?>

<div id=”primary”>

<ul class=”xoxo”>

<?php dynamic_sidebar(‘primary_widget_area’); ?>

</ul>

</div><!– #primary .widget-area –>

<?php endif; ?>

 

<?php if ( is_sidebar_active(‘secondary_widget_area’) ) : ?>

<div id=”secondary”>

<ul class=”xoxo”>

<?php dynamic_sidebar(‘secondary_widget_area’); ?>

</ul>

</div><!– #secondary .widget-area –>

<?php endif; ?>

 

Now coding with PHP is done. And now what you have to do is to style your theme.

Style (style.css)

 

As we have never discussed about CSS hence I am giving you a brief introduction. CSS stands for Cascading Style sheets Here it is used for giving a presentation structure (layout and colours) to your theme. It is separate from HTML structure which fixes up the control of your blog and makes it fast and easy to update.

 

First of all create style.css and open it in a text editor and add a CSS comment which tells wordpress about your theme:

/*

Theme Name: kalplata

Theme URI: http://sangkrit.net/kalplata/

Description: A search engine optimized website framework for WordPress.

Author: You

Author URI: http://sangkrit.net/

Version: x.x

Tags: should be comma seperated

.

GNU General Public License, version 2 (GPL).

http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

*/

Note: Choose your own theme name likewise here we are creating a theme named as ‘kalplata’.

 

(Still Writing)

Here are your sources to CSS

 

 

 

 

 

SANGKRIT

How To Add A Tweet This Button In Your Blog Posts Without Using A Plugin

Want to add a ‘tweet this’ button in your blog posts for your blog’s exposure so as to increase your blog’s traffic. Do this without using a plugin as installing a specific plugin even for an undersized desire makes your blog slow and handling complicated.

Put the following given code anywhere in loop of your theme’s single.php template:

<a href=”http://twitter.com/home?status=An Interesting Article <?php the_permalink(); ?>” title=”Send this page to Twitter!” target=”_blank”>Tweet This!</a>

 

Note: Read the given code carefully to understand what actually happened.