Posts Tagged ‘code lt’

Can I schedule WordPress to take down a post?

Welcome to my blog, please feel free to subscribe to my RSS feed, join me on Twitter or leave a comment.

Everybody knows you can schedule WordPress to put a post up on a specific date but is it possible to schedule WordPress to take down a post on a specific day?

Of course it is but you’ll need to know a little PHP and understand how WordPress works.

Setting up your post for a scheduled takedown

First, you’ll need to add a custom field to your WordPress post. There are a couple ways to do this, the easiest is to add a custom field with the name “takedown” and the date you want WordPress to remove it in the Value field. Technically, the name isn’t important (nor is the date format) if you know what you’re doing but let’s try to work with these two standards for now.

  1. Set the Custom Field Name to takedown
  2. Set the Value of the Custom Field to 2010-05-01 (year-month-day)

Now save your post and let’s take a look at the next step.

Detecting the current date

PHP allows us to fetch the current date using the date() function and using some formatting options we can return the value of the date based on the format we need which is date(‘Y-m-d’);. If you add the code <?php date(‘Y-m-d’);> after the very last line of your footer file, you’ll see todays date appear at the bottom of your website.

Now let’s make sure to remove it from the last line and work on comparing the date instead.

Comparing the current date

Now that we know now the actual date, we need to know what day we want the website to stop showing our post. For this, we need to fetch the value stored in takedown using PHP:

$takedown = trim(get_post_meta($post->ID, ‘takedown’, true));
Now the variable $takedown has the value stored in the custom field takedown, which is great as long as there was a value there. To test if takedown has a value let’s add a quick check:
$takedown = trim(get_post_meta($post->ID, ‘takedown’, true));
if (strlen($takedown)==10) {
// your code here
}

For some reason, even if the value of the variable is not found WordPress assigned something too it so instead of using isset() or testing for NULL, I’ve found the safest thing to do is check the string length. Since we know the only variable that is valid will be a YYYY-MM-DD format, testing for a ten character string will ensure we’re on the right track. You could also use checkdate() if you’re server supports it.

Finally, I compare the two dates using the code:

if ($date(‘Y-m-d’) >= $takedown) { //yourcodehere;}

Deleting the post

There are a couple ways in WordPress to change the status of a post or delete it outright, in my case I simply want to convert posts from Published (which means they’re live) to Pending (for my review) so that I can manually delete the posts later if I want.

To do this, we will make use of the WordPress function wp_update_post() like so:

$my_post = array();
$my_post['ID'] = $post->ID;
$my_post['post_status'] = ‘pending’;
wp_update_post($my_post);

This code simply tells WordPress to update the current post and set the status to pending which will convert the post from live to hidden.

If you want to completely delete the post on a schedule, you can do so using the wp_delete_post() function instead of my code above.

The final code

Here’s the full code assembled for you, to make it work you should place it in the single.php file just below the final line of code on your website. It is important to note that this code will only activate after the takedown date, when the specific post is viewed so technically, if a page is to be taken down on the 1st of May but nobody visits until the 10th, it will still be live until the 10th.

$takedown = trim(get_post_meta($post->ID, ‘takedown’, true));
if (strlen($takedown)==10) {
if ($date(‘Y-m-d’) >= $takedown) {
$my_post = array();
$my_post['ID'] = $post->ID;
$my_post['post_status'] = ‘pending’;
wp_update_post($my_post);
}
}

How do I add the date to my blog?

There are a lot of times when we want to add something as simple as the date to our blog but coding (especially in PHP) can be a bit difficult. Let me walk you through the steps to adding a date to your blog, assuming of course you use WordPress.

First, open your template files such as the footer by loading the footer.php file located in your /wp-content/themes/[theme name]/ folder.

Next, we need to insert a very simple PHP function called date() into your page but before we do that, we need to make sure that we open and close the PHP event. To do this, simply open it using <?php and close it using ?>. The date() function itself requires a formating argument, but luckily we’re not meant to remember them all. They can be found on the PHP date() reference page.

As an example, if you want to show the day of the week that it currently is you could open your website and edit it every day (highly impractical) or you could insert the code <?php echo date(‘l’); ?> into your page. Note that I open the PHP event, place the date() function with the argument ‘l’, indicate the end of a line (;) and then close the PHP event.  Each of these elements are required to properly format the date.

If you would like to show the current year, simply use: <?php echo date(‘Y’); ?> because Y is the symbol for the year. On the other hand, if you’d like to use something more complex, try <?php echo date(‘l jS \of F Y h:i:s A’); ?> which will return something like Monday 8th of August 2005 03:12:46 PM.

Once you’ve saved your footer.php file, simply re-upload it to your server and voila! Now you can set the date using your server and PHP instead of editing files every day! In more practical terms, it is how you can always have an updated copyright notice of your website without having to remember to update it each January.

Easy Technorati Tags for WordPress

TechnoratiThere are a few other Technorati Tags generators for WordPress out there but I found most of them overly complicated and fairly difficult to use, often requiring custom fields or complex processes. What this plugin does is takes the native tags from WordPress and generates a list of Technorati tags for your blog.

Usage

To use the Easy Technorati Tags for WordPress plugin, simply download and install onto your WordPress website. You can then add it to your theme by inserting the code <?php echo timu_technorati_tags() ;?> to your blog theme files or to a sidebar widget.

Output

The tag generates a comma separated list of tags complete with Technorati links. I choose to return it as a value rather than write it directly so that if you’d like to make changes or process the results, you can do it easy.

download file Easy Technorati Tags for WordPress image

You can download the plugin directly from the WordPress Plugin Directory. Don’t forget to rate the plugin if you’ve enjoyed it.

How You Can Help

I love developing plugins for WordPress and do my best to always keep them free but of course it take a lot of time and effort to build these plugins so if you’d like to say thanks, the best way is to take a few moments and write about the plugin on your own website, include a link to my website from your posts or download and rate the plugin on the official plugin directory.

Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

WordPress PHPINFO() Plugin

It’s important for a non technical administrator to be able to diagnose server related problems in WordPress but also rapidly retrieve feedback regarding their web server. This simple plugin adds an option to an adminstrator’s Tools menu which displays standard phpinfo() feedback details to the user. 

This a very simple script, designed to help the non technical user get immediate feedback about their blog.

It’s very easy to run a phpinfo() session without running a plugin and I can already hear a lot of people pointed out that this is a little like swatting a fly with a bulldozer but recently I’ve been working with a lot of charities and not-for-profits who lack in-house technical support and the simple process of running a phpinfo() query was daunting.

For those of you who want to run this as a page rather than a plugin, you can upload a php script to your website with the following code:

<?php phpinfo(); ?> 

Once you upload the code, simply access the page via the URL. On the other hand, if what I just typed made no sense what-so-ever … 

download file WordPress PHPINFO() Plugin image

How You Can Help

I love developing plugins for WordPress and do my best to always keep them free but of course it take a lot of time and effort to build these plugins so if you’d like to say thanks, the best way is to take a few moments and write about the plugin on your own website, include a link to my website from your posts or download and rate the plugin on the official plugin directory.

Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

WordPress Plugin to automatically update the copyright notice.

What is this WordPress plugin?

This plugin automatically generates a copyright notice from the first post in your blog to the current year. The Auto Copyright notice plugin fetches the first and last year of posts from the database and displays the results as a copyright notice on your website.

This process allows blog owners to add content retroactively, knowing that the  website will automatically find the first date a post is published as well as the last published date or the current year (whichever is later).

To use the plugin, simply download it and add the code  <?php echo  autocopyright();?> to your website where you’d like the copyright notice to appear.

download file WordPress Plugin to automatically update the copyright notice. image

How You Can Help

I love developing plugins for WordPress and do my best to always keep them free but of course it take a lot of time and effort to build these plugins so if you’d like to say thanks, the best way is to take a few moments and write about the plugin on your own website, include a link to my website from your posts or download and rate the plugin on the official plugin directory.

Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.

Fundraising Thermometer Plugin for Wordpress

The plugin interface, for WordPress

Features

Example of a fund raising image from the new plugin

The fund raising tool is a true WordPress plug-in, testing with WordPress 2.7 and fully functional. It features:

  • W3C compliant Cascading Style Sheets (CSS)
  • Dynamically updated text including target and current fund status
  • Money formating options for use internationally
  • Theme options, allowing designers to customize the look of the thermometer
  • Call either the graphic or a formated number to display in text.

Admin Features

The new interface allows uses to set both the current amount (what has been raised) as well as the target amount (what you want to raise). The script automatically generates the ten steps in between and displays them for the user.


The plugin auto detects if the money_format() function is present and will use it automatically if found, otherwise it will display the currency using the number format function automatically.

How It Works

To display the current amount of money raised (in currently format) place the following code in your theme:

<?php echo show_ourprogress();?>

For a graphical version (by default the thermometer), include the following code:

<?php show_ourprogress_graphic();?>

Where to Get It

The plugin can be downloaded from the official WordPress repository: 

download file Fundraising Thermometer Plugin for Wordpress image

How You Can Help

I love developing plugins for WordPress and do my best to always keep them free but of course it take a lot of time and effort to build these plugins so if you’d like to say thanks, the best way is to take a few moments and write about the plugin on your own website, include a link to my website from your posts or download and rate the plugin on the official plugin directory. 

Support forums are now online! If you have any questions, please visit http://forums.thisismyurl.com.