Lesson: Styling the postmetadata section
-
The
postmetadata
is the information about your post often found in a corner of the sidebar menu or down at the bottom of your post before the comments and footer. It can be styled in many different ways with a variety of details. Let’s look at some to help you figure out what you want to do.The basic code, condensed from the WordPress default (Kubrick) is:
<p class="postmetadata alt">
<small>
This entry was posted on <?php the_time('l, F jS, Y') ?> and is filed under <?php the_category() ?>....</small>This would result in:
This entry was posted on Monday, February 12, 2003 and is filed under WordPress Lessons Things to Know…
Let’s just change
the_category()
so that it lists the categories with a comma in between them. Notice the “space” after the comma to put comma, space in the separation:<?php the_category(', '); ?>
This would look like:
…is filed under WordPress, Lessons, Things to Know…
If you want to change that to a pipe, you can put in:
<?php the_category(' | '); ?>
And you would get:
…is filed under WordPress | Lessons | Things to Know…
There is more information in the Codex about styling the_category tag.
Okay, let’s look at the date. Here are some examples of PHP date layouts to help you change the date layout to your own style:
<?php the_time('l, F jS, Y') ?>
– Tuesday, May 14, 2001
<?php the_time('j Y at g:i A') ?>
– 28/2005 at 2:45 PM
<?php the_time('D j M y') ?>
– Mon 28 Jan 05
<?php the_time('The j day of the month of F in the year of Y') ?>
– The 28 day of the month of January in the year of 2005More specifics on date layouts can be found at PHP.net’s Date Function.
There are several plugins that allow you to include the date the post was last modified. You can find two of them at Guff Zsub’s Last Modified WordPress Plugin and Nick Momrik’s Last Modified Plugin for WordPress. Here is an example using Nick’s plugin.
This entry last modified on <?php last_modified('l, F dS, Y'); ?>, originally posted on <?php the_time('l, F jS, Y') ?>. It is sorted and filed under <?php the_category(', ') ?>....
Now, let’s look at the actual “look” of the
postmetadata
section. There are a lot of things you can do with this. For one example, you don’t have to use the<small>
tag but eliminate it and set the font-size to whatever you want it to be. You can also put the “box” just about anywhere in your layout and look like anything. Let’s put it in a narrow blue bordered box that sits at the top right corner of your post with the beginning of the text wrapping around it. In your index.php, single.php, or whatever file that hosts your post information, move thepostmetadata
section (like above) up the page and below the title, before the post content. In yourstyle.css
file change the information to something like this:.postmetadata {position:relative; float:right; margin:5px; padding:5px; width:25%; border: solid 1px blue; font-size: 80%; color: navy; background: #CCFFFF;}
The
float:right
attribute moves the box to the right of the text. I’ve set the width to 25% so it would take up a quarter of the screen width, no matter what the screen width is. You can make it a fixed width by changing it towidth:150px
or another number that matches the look you want.This should help get you started. What are some other ways you can think of to change the look of your
postmetadata
?
- The topic ‘Lesson: Styling the postmetadata section’ is closed to new replies.