Useful Ways to Working with dates & Times in WordPress

All content of a blog that is manageable by WordPress has recorded the dates on which system has undergone changes; whether to publish or edit the material, for example. This time reference plus customizable can be very exploited in a different display screen or even as filter searches for users, as discussed below.




Useful Ways to Working with dates & Times in WordPress
POSTING SCHEDULE
When you publish an article, users have the ability to choose the date on which this material will serve. By default the time of publication is always present, but this can be changed for both the past and the future.
Locate the tab while editing publish your article, change the date by clicking on ‘Edit’ and choose a future date to current by clicking ‘Ok’. At this point you realize that the ‘Post’ button changed its label to ‘Schedule’. Clicking on it the material in question will be published only when the chosen date comes.
SEARCH FOR SPECIFIC DATE
In an advanced search you can query the occurrence of publications for an exact date. Use the tool below to return results on May 3, 2011:
<? Php
$ Args = array (
     ‘Year’ => 2011
     ‘Monthnum’ => 05
     ‘Day’ => 03
);
query_posts ($ args); ?>

Similarly you can filter the posts in particular situations, such as the previous month of the current file:
<? Php
$ Year = date ( ‘Y’);
$ Mes_anterior = date ( ‘m’) 1;
if ($ mes_anterior == 0) {
     Mes_anterior = $ 12;
     $ Year–;
}

$ Args = array (
     ‘Year’ => $ year
     ‘Monthnum’ => $ mes_anterior
);
query_posts ($ args); ?>
LINKS TO PAGE DATES ARCHIVES
Creating a custom query (shown above ) is not necessary except for specific cases such as the existence of an advanced query form for example. To make working one page responsible for the listing of articles by date use the paging pattern of your theme , passing the following urls :
<?php
$ano = get_the_time( ‘Y’ );
echo ‘<a href=”‘ . get_year_link( $ano ) . ‘”>Arquivo de ‘ . $ano . ‘</a>’;

$mes = get_the_time( ‘m’ );
$mes_nome = get_the_time( ‘F’ );
echo ‘<a href=”‘ . get_month_link( $ano, $mes ) . ‘”>Arquivo do mês de ‘ . $mes_nome . ‘ de ‘ . $ano . ‘</a>’;

$dia = get_the_time( ‘d’ );
echo ‘<a href=”‘ . get_day_link( $ano, $mes, $dia ) . ‘”>Resultados para ‘ . $dia . ‘ de ‘ . $mes_nome . ‘ de ‘ . $ano . ‘</a>’; ?>
SORT BY DATE
By default ordering of the results is made in descending chronological order, ie starting from the initial position in the first latest to oldest last .
1

<? Php query_posts ( ‘ orderby = date & order = DESC’ ); ? >

If you want in a given situation initially display the oldest change the parameter of the function as follows :

1

<? Php query_posts ( ‘ orderby = date & order = ASC ‘ ); ? >

ORDER BY CONTENT DATE CHANGE
The ranking above is performed based on the date of publication of the material. After the publication date is common for the same material change over time. In many cases the update dates are forgotten and poorly users come to know that certain content has been updated. To resolve this problem, determine a filter to sort the results by modification date:
1

<? Php query_posts ( ‘orderby = modified’); ?>
FORMAT SET DATE TO BE SHOWN
Configure which format you want to display the time references in your blog accessing your panel in the main menu items ‘Settings’> ‘General’. Identify the date format guides and Time format and select which model you prefer among those provided by the system. Outside these predefined formats you can define your own model according to documentation on the format of Date and Time WordPress.
VIEW DATE OF PUBLICATION
Show in your theme when certain article was published using:
1
<P> Publication Date: <? Php The_Date (); ?> </ P>
The above function will display the date of publication for the posts or else a cluster of posts, ie, to display a results listing only the first instance among many of a single date will the value of the printed date.
ALWAYS VIEW ARTICLES PUBLICATION DATE
Skirting the problem presented above can display the date for all the results of your paging, even for those of the same day using:
1
<? Php echo ‘<p> Publication Date:’. get_the_date (). ‘</ P>’; ?>

VIEW DATA ITEM UPDATE
As was explored above it is interesting to work with the update dates of the content and in such cases the display of the respective dates are made very relevant.
1
<P> Last update: <? Php the_modified_time (); ?> </ P>
FORMATS FOR CUSTOM DATES
In all cases display dates presented the format to be followed will be the one identified by the admin panel. In entato you can customize this format individually for each time one of these functions are called using the format as a parameter for them:
<?php
// Exemplo para o dia 3 de Maio de 2011

the_date( ‘d-m-Y’ );
// 03-05-2011

the_modified_date(‘j, F Y – G:i:s’);
// 03, Maio 2011 – Hora:minuto:segundo
?>




LEAVE A REPLY

Please enter your comment!
Please enter your name here