The next section builds the title of the post. All the WordPress magic happens between a pair of <h2> tags that make the title stand out. The tag called the_permalink() returns the permalink of the post. This perma-link tag is used in conjunction with the_title_attribute (which returns a clean version of the title by stripping out any HTML code that may be used in the title) and the_title (which returns the title of the post as it was entered) to create the title link. If you want to add Title: before each of your blog post titles, the code would look like this:
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Title: <?php the_title(); ?></a></h2>
Save the index.php file and reload your blog's home page, and you'll see Title: in each post's title (Figure 12.3). If you click the permalink and go to the post's page, however, you'll notice that Title: is missing. The reason: Individual post pages use a different template (single.php).
Title: Tweaking a stock theme
Getting a free theme for your blog is great, but chancer are there are some things you don't like about It... or perhaps you just want to add some more information to the theme. While template files might seem scary, they aren't!
Tags: screenshots. templates Posted in Tutorials I Edit I No Comments »
Figure 12.3 The first fruits of theme tweaking: an addition to a post title. Useless? Perhaps, but the exercise is instructive.
If you want the changes you've made in the index.php file to note show up on individual post pages, you have to edit that template separately. The single.php file uses the same tags as index.php, so editing it should be a piece of cake.
Was this article helpful?