Book Image

WordPress 2.8 Themes Cookbook

By : Nick Ohrn, Lee Jordan
Book Image

WordPress 2.8 Themes Cookbook

By: Nick Ohrn, Lee Jordan

Overview of this book

Themes are among the most powerful features that can be used to customize a web site and give it a professional look, especially in WordPress. Using custom themes you can brand your site for a particular corporate image, ensure standards compliance, and create easily navigable layouts. But most WordPress users still continue to use default themes as developing and deploying themes that are flexible and easily maintainable is not always straightforward and lot of issues pop up during the process.This easy-to-use step-by-step guide will help you create powerful themes for your WordPress web site, and solve your theme development problems in a quick and effective way. It enables you to take full control over your site's design and branding and make it look smarter.WordPress is distributed with two ready-to-use themes. You can use these themes to give a common look to your website, or use the techniques described in this book to create custom themes. This book includes over 100 useful recipes to help you get started and create advanced themes. It starts with the basics of WordPress themes and creating a theme from scratch. Then, it covers how to enhance your template and add effects to get a rich look. You will learn how to manage pages, categories, and tags for your blogs, and how to make your posts look unique. You will also learn about the comment system and sidebars that will help you give a new feel to your blog and web site.This book will help you through the most common problems encountered when developing a WordPress theme. You will get tips to enhance your design skill and eventually enhance your blog's design.
Table of Contents (17 chapters)
WordPress 2.8 Themes Cookbook
Credits
About the Authors
About the Reviewers
Preface

Displaying the blog name


A variety of information about a blog can be entered in the WordPress administration panel. Displaying that information publicly is the responsibility of the active theme. One piece of information that you may want to display is the name of the blog.

How to do it...

First, you must locate the position at which the blog name should be displayed in your theme. Open the appropriate theme file (header.php is a good place to start) and place your cursor at the desired location. For the purposes of this recipe, you'll be inserting the blog's name as the value of the title tag.

Locate the title tag and remove whatever value is contained within it. Now, insert the bloginfo function and make the markup look like the following:

<title><?php bloginfo('name'); ?></title>

How it works...

When the blog name is set in the administrative panel, the value that the user enters is stored in the options table within the WordPress database. When you call bloginfo with name as the argument, the name of the blog is retrieved from the options table and displayed.

Note

Benefits of open source

WordPress is open source software. As such, you can examine the code base directly when you want to see how things are implemented. To get the most out of WordPress, you should look up functions that you use frequently, and bloginfo is a great place to start. It gives you a good idea of the way WordPress stores and retrieves miscellaneous information, and can be found in wp-includes/general-template.php.

There's more...

Template tags, of which bloginfo is one, often take one or more parameters that modify the output produced. With bloginfo, the single parameter you can pass determines which piece of information about the blog should be displayed.

Blog info available

The sole parameter accepted by the bloginfo function is a simple string. The following strings are supported, and must be passed in place of name in the above code sample:

String

Data Displayed

name

The blog's title

description

The blog's tag line

url

The URL to the blog's home page

wpurl

The URL to the WordPress installation

rdf_url

The URL for the blog's RDF/RSS 1.0 feed

rss_url

The URL for the blog's RSS 0.92 feed

atom_url

The URL for the blog's ATOM feed

comments_rss2_url

The URL for the blog's comments RSS 2.0 feed

pingback_url

The URL for the pingback XML-RPC file

stylesheet_url

The URL for the primary CSS file of the active theme

stylesheet_directory

The URL of the style sheet directory of the active theme

template_directory

template_url

The URL of the active theme's directory

admin_email

The e-mail address of the blog administrator

charset

The blog's encoding for pages and feeds

version

The blog's version of WordPress

html_type

The content type of WordPress HTML pages

Retrieving information without displaying it

To retrieve a piece of information for storage in a variable or for further manipulation, use the get_bloginfo function instead of bloginfo. get_bloginfo returns information instead of printing it, and supports the same parameters as bloginfo.

As an example, perhaps you want to capitalize the blog name for some reason. The following would allow you to do so:

<?php echo strtoupper(get_bloginfo('name')); ?>