Archive for August, 2009

You are currently browsing the Understanding WordPress archives for August, 2009.


Themes – An Overview

Themes determine the look of your blog and save you the time of having to deal with most of the code involved, although WordPress allows you to get your hands into as much code as you like.

Most people (but not us) will be happy keeping the default WordPress theme, which is known simply as WordPress Default (formerly called Kubrick, created by Michael Heilemann)

The WordPress community makes many themes for you to choose from and many are free. The best place to find a theme is the WordPress Theme Directory at http://wordpress.org/extend/themes/.

This directory is run by the same people who control WordPress itself, and they’ve set up some ground rules that a theme has to follow to be listed:

  • All theme files must be included in a single .zip file.
  • The theme must include a file called screenshot.png which is how the theme will look like.
  • The theme has to support widgets.
  • The theme must not contain any hidden or sponsored links.

You can change some of the functionality of your theme in two different ways: by adding widgets or using template tags.

Widgets are known as “side bar” accessories which are defined as WordPress add-ins which allow you to add design elements and functionality to your “sidebar” of your theme. The sidebar is normally an area on the right (sometimes on the left or bottom) that gives more information to the reader about the information in your blog. This can be a category list, a monthly archive of posts, blogroll, calendar highlighting days with posts, tag cloud, images, etc.

A template tag is a code that instructs WordPress to “do” or “get” something. It is a piece of PHP code that is encapsulated in a function. These code snipets are stored in the various PHP (.php) files that make up your WordPress theme.

Here are some videos (.zip) giving an overview of the topics covered in the class. In the class I cover these topics in much more detail as well many other topics.

Understanding Themes
Installing Themes
Customizing Themes
Modifying CSS
Modifying PHP

Code to Display the Most Recent Comments

There are a few plugins that will retrieve the most comments. But if you want a little more control or like to get your hands dirty in a little PHP code, there is a code snippet that will do the trick:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
 
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt,
comment_approved, comment_type,comment_author_url, SUBSTRING (comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
ORDER BY comment_date_gmt DESC LIMIT 10";
 
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\n<ul>";
foreach ($comments as $comment) {
   $output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID) .
   "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" 
   . strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= "\n</ul>";
$output .= $post_HTML;
echo $output;
?>