Template Tags

There is a template tag for every piece of information you can enter into a post or page. Figure 6-10 shows the tags that can be used to display the information from the Posts ^ Edit screen.

Figure 6-10. Template tags for a post

As you'll see throughout this chapter, there is a vast number of template tags you can use to customize your theme. I'll go over most of the essentials, but please visit codex.wordpress.org/Template_Tags/ for a complete list of available tags plus detailed documentation about each one. The conditional tag reference (codex.wordpress.org/Conditional_Tags) is also essential. You'll look at several conditional tags as you dig in to the different theme files that are used to display various kinds of archives.

Date and Time Tags

The date and time tags, the_date() and the_time(), are based on PHP's date() function. If they are called without arguments, they use the date and time formats you chose under Settings ^ General.

These two tags work exactly the same way, except for one thing: when the_date() appears inside the Loop, it will print the date only once for each set of posts that fall on that date. This behavior makes sense when you're using dates as headers, but it doesn't work so well when you have the date listed alongside the post's other meta data (author, categories, tags, etc.). In the latter case, you need to use the_time() and specify the date format you want. For example, the_time("F j, Y"); will print the month, day, and year in the common American format: May 1, 2010. To use the date format you chose in Settings ^ General, use the get_option() function as shown in Listing 6-16.

Listing 6-16. the_date and the_time in the Loop

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h3 class="date"><?php the date(); // prints once per day ?></h3>

<h2 id="post-<?php~the_ID(); ?>" class="<?php post_class(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent link to <?php the_title(); ?>"><?php the_title(); ?></a> </h2>

<?php the_content(); ?> <?php wp_link_pages(); ?> <p class="postmeta">Posted on

// these dates and times will print for every post the time(get option("date format")); // uses date format instead of time ?>

at <?php the_time(); // uses time format by default ?>

<div class="commentblock">

<?php comments_template(); ?> </div><!--commentblock--> <?php endwhile; ?> <div class="navigation">

<div class="alignleft"><?php posts_nav_link(); ?></div> <div class="clear"><!-- --></div> </div><!-- .navigation --> <?php endif; ?>

Was this article helpful?

0 0

Post a comment