RSS

Wordpress:the date tag and the time tag

Thu, Jun 25, 2009

Internet

I want to add a time tag before the title like 6/26/2009 wordpress: the date tag and the time tag

If so, it’s easies for me to understand what the date it post…

I try to login in different wordpress theme, and check the different style to show the time

and now, I think I fixed it.

here is some notice for me, and for you.

 

Two common WordPress tag functions you will see in most themes are the time and date format tags: <?php the_date(); ?> and <?php the_time() ?>. These tags are used to return time and date information relating to the publishing of a post. Both of these functions accept a parameter that formats the way the date or time is displayed. This parameter is called a format string and can be thought of as a simple template describing how and what will appear. We are going to look at some of the options you have when formatting these functions.

Each character in these format strings represents one part of the object we are formatting. Let’s look at a simple example. Here is the date tag

<?php the_time('m.d.Y'); ?>

You will notice that I used the the_time tag. This is because using the the_date tag within the WordPress loop will fail to return two instances of the same date on the same page. As a general rule use the_time when possible.

 

If you want to display the date in European format, follow this sequence. With a simple rearranging of the format string, we end up with this code:

<?php the_time('d.m.Y'); ?>

What if you want to display the time and date in a different format altogether? Here are some options:

 

Format characters for the ‘day’

D = abbreviated day of the week: e.g. Mon, Tue, Sun, etc.

d = date displayed as two digits, and single digit dates are led by a zero

j = date displayed as one digit

l (lowercase L) = full day of the week: e.g. Monday, Tuesday

N = number representing the day of the week: e.g. Mon.=>1

S = suffix for numeric day of the month: e.g. st, nd, ect.

z = number representing the day of the year: 0-365

Format characters for the ‘week’

W = number representing the number of the week: ‘32′ week of year

Format characters for the ‘month’

F = full month: e.g. May, June

m = two digit number representing month, single digit dates are led by a zero

M = abbreviated month: e.g. Dec, June, etc.

n = one digit month

Format characters for the ‘year’

Y = four digit year: 2009

y = two digit year: 09

Format characters for the ‘time’

g = one digit, 12-hour hour format

G = one digit, 24-hour hour format

h = two digit, 12-hour hour format

H = two digit, 24-hour hour format

a = lowercase am or pm

A = uppercase AM or PM

i = two digit, minutes

s = two digit, seconds

This list is not exhaustive, but it includes most of the format characters you might use in a WordPress theme. There are literally thousands of ways you could use these tags. Here are a couple of examples:

<?php the_time('l'); ?> the <?php the_time('dS'); ?> of <?php the_time('F'); ?>

Will result in: Tuesday the 21st of April

<?php the_time('F dS, Y'); ?>

Will result in: April 21st, 2009

 

The possibilities are endless, so experiment and have fun!

Incoming search terms for the article:

Related Posts

, ,

This post was written by:

Kent - who has written 274 posts on Kent’s Blog.

Working in the English Search Engine industry, focusing on the new media and new economy, Trying to find out a way for e-commerce integration!

Contact the author

Leave a Reply

Powered by Yahoo! Answers