Cookie

Caution


This article was published more than a year ago, there may have been developments.
Please take this into account.

Often (writing software and technology) that the article is now present, tomorrow has already passed. There is at least un plugin per WordPress to notify the reader that the post you're reading was written long ago, which it is a perfect fit and ready for use, groped but I also wanted to change the code of my theme to add this simple function automatically.

I state that the following steps create a box (in this case yellow) before the article title.

You will be informed immediately about the update article, as in the following screenshot, taken from an old article.

banner

It must also say that with a little ingenuity we can show the notice only in posts about a certain category. Well, the premises are finished.

Change the theme

First you need to edit the file “single.php” and “style.css” related to the theme used. To do this, within our admin panel click on “Appearance” – “Editor“.

edit_temi

Depending on the active theme on the blog we have to find the exact point at which to place the following PHP code (immediately above the title Post):

<?php
    // date('U')          = Current date in seconds since 1 January 1970 (Unix time)
    // get_the_time('U')  = Date of publication of the article in seconds 1 January 1970 (Unix time)
    // 31557600           = Seconds in a year (365 days and 6 hours)
    if ((date('U') - get_the_time('U')) >= 31557600 && in_category('16')) { ?>
        <div class="notice">
		<h1 class="title">Caution!</h1>
		<p>This article was written in the <strong><?php the_time('Y'); ?></strong>, there may have been some developments in the subject matter.<br />
		If in doubt, leave a comment at the bottom of the article.<br />
		Thank you.</p>
        </div>
<?php } ?>

The code is well commenato and explanatory only. In this case the box will be shown if the post is older than a year and if it is in category “16” (which in my case corresponds to the category “software“. You can also remove the code “&& in_category('16')” if we want the alarm to be displayed in all categories.

The style of the CSS is just as easy, the following lines can be added in any part of the file “style.css“:

.notice{
border-top:3px solid # e6d62e;
border-bottom:3px solid # e6d62e;
background-color:#ebe7be;
padding: 10px 20px 0 10px;
}

Find a category

Finding the ID number on the category is equally simple. We go to the menu “Goods” – “Categories“.

categories

Now pass the mouse on the relevant category, and pay attention to the link associated (lo entertainment at bottom of page).

cat_software

If we are careful we will read in the data for the variable “&tag_ID=“. In my case “16“.

Not enough?


TheJoe

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

2 Comments

stopsatgreen · 11 April 2014 at 11:42 PM

Works a treat. Many thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.