Archive for the ‘Wordpress’ Category

Co-Founder of WordPress

December 9, 2009

Thanks to Matt Mullenweg, Co-Founder WordPress, for providing wordpress blogging patform.

using is_page() conditional tags in themes

November 2, 2009

How and where to use is_page() conditional tag :

1)  Login to Administrator section

2) Pages > Add New

3) Give title as “About” and publish it.

If page.php is not there in wp-content/themes/current_theme folder, than wordPress will use index.php of the current theme to display the content.

If page.php is there and we want that “About” page should have some different look than other pages, then use the following  to achieve it:

1) Create a template file named “About.php” file same as page.php file in wp-content/themes/current_theme folder

2) Do formatting as per your needs.

3) Edit the page.php file as mentioned below :

get_header(); ?>

// use is_page conditional tag to check whether template file exists for “About” page

<?php if (is_page(‘About’)) { ?>

<?php include(“About.php”); ?>   // if template file exists than include the “About.php” file
<?php } else { ?>

// Other pages will use this section for displaying the content
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(‘<p>Read the rest of this page &raquo;</p>’); ?>
<?php wp_link_pages(array(‘before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
<?php } ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

IMP:

The template file name and the name used in is_page() must be same as page title mentioned in creating page in administrator section.

for e.g : if page title is “About” then

1) create template file with name About.php

2) use page title in is_page() as is_page(‘About’)

The Template File Hierarchy

November 2, 2009

WordPress uses the Query String — information contained within each link on your web site — to decide which template or set of templates will be used to display the page.
First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested.
Templates are then chosen — and web page content is generated — in the order suggested by the WordPress Template hierarchy, depending upon what templates are available in a particular WordPress Theme.

Template_Hierarchy

List of Template files in Themes

November 2, 2009
The following files have special meaning to WordPress. We can have more files apart from these files.

style.css
The main stylesheet. This must be included with your Theme, and it must contain the information header for your Theme.

Example of information header :

/*
Theme Name: My Theme
Theme URI: the-theme’s-homepage
Description: a-brief-description
Author: your-name
Author URI: your-URI
Template: use-this-to-define-a-parent-theme–optional
Version: a-number–optional
.
General comments/License Statement if any.
.
*/
index.php
The main template. If your Theme provides its own templates, index.php must be present.


comments.php

The comments template. If not present, comments.php from the “default” Theme is used.
comments-popup.php
The popup comments template. If not present, comments-popup.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. Used when an individual Page is queried.
category.php
The category template. Used when a category is queried.
author.php
The author template. Used when an author is queried.
date.php
The date/time template. Used when a date or time is queried. Year, month, day, hour, minute, second.
archive.php
The archive template. Used when a category, author, or date is queried. 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.

IMP:
These files have a special meaning with regard to WordPress because they are used as a replacement for index.php, when available, according to the Template Hierarchy, and when the corresponding Conditional Tag (a.k.a is_*(); function) returns true. For example, if only a single post is being displayed, the is_single() function returns ‘true’, and, if there is a single.php file in the active Theme, that template is used to generate the page.

Location of themes in WordPress

November 2, 2009

/wp-content/themes/

2 core page views in WordPress

November 2, 2009

WordPress has 2 core page views :

1) Sinple post view : when the web pages displays a single post

2) Multi-post view : lists multiple posts or post summaries

3 types of files in Themes

November 2, 2009

Themes consists of follwing 3 types of files :

1) Style Sheet  files

These files controls the lokk of the site

– style.css

2) Template files

These files control the way the web page generates the information from the Database to be displayed as a web page

– index.php, header.php, sidebar.php, footer.php etc.,

3) Functions file

– optional functions can be written in function.php file

Minimum files a Theme can have are :

1) style.css

2) index.php