Posts Tagged ‘options’

Can I schedule WordPress to take down a post?

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);
}
}

v1.0.0 – Return a whole sentence with Get Better Excerpt

= Return a whole sentence =
If you would like to return whole sentences rather than words, you can control the number of sentences to return:
get_better_excerpt(’sentence=1′);

I’ve upgraded my Get Better Excerpt plugin this morning to include a cool new feature, now you can retrieve a complete sentence instead of a series of words for your WordPress excerpts.

To return a single sentence:

get_better_excerpt(’sentence=1′);

For two sentences:

get_better_excerpt(’sentence=2′);

Of course, you can also combine this with other options:

get_better_excerpt(’sentence=2&link=true’);

WordPress Plugin Updates

For those who don’t follow my posts regularly, you might not know that I’m a fairly passionate WordPress plugin developer, in fact I have ten plugins on the official WordPress plugin website as well as another half dozen or so that I’m working on finishing up the beta development for.

Updates

This week I’ve completed updates to a few plugins including adding new functionality to the Easy Popular Posts plugin which allows users to add a list of popular posts to their theme. Users can now sort by ASC for Ascending posts, DESC for Descending posts and RAND for Random posts. v0.1.1

I’ve also added the ability to sort the List Posts with Pingbacks and Tracks by ASC, DESC and RAND options v0.1.1

I’ve also added the ability to sort the Easy Scheduled Posts by ASC, DESC and RAND options v0.1.1

The Auto Copyright plugin is one of my personal favorites, it’s an easy plugin to add to just about any theme which allows users to insert the start and stop dates of their copyright based on the first published post in the database. Now, the plugin also allows users to format how the output looks. v1.1.2

Call for Plugins

I’m a pretty passionate WordPress developer and I’m always looking for plugins to work on, if you have any that you developed but simply don’t have time to work on anymore or would like to resurrect an abandon plugin please let me know about it. I would love to take on a few more plugins to manage.

How do you move a website to a new domain?

“… changing your IP address, webhost, domain name, blog template, and blog version all at the same time is the exact opposite of what you should normally do. It’s better to change only one thing at a time so that if something goes horribly wrong, you can trace what caused it.”

 - Matt Cutts (http://www.dullest.com/blog/switching-things-around/)

Why move a website?

First and foremost, why would you move a website? Well there’s a few reasons that I can think of right off the top of my head:

  • Your old domain name was inappropriate
  • You lost your old domain
  • You decided to change focus
  • You started on a sub domain and related to a full

What ever the reason, sometimes we have to move domains so the real question is … how do you do it right?

How to move a domain properly

Moving WordPress

First, lets assume that you’re using WordPress.

  1. Log into your phpMyAdmin or control panel and export the WordPress database to an SQL file.
  2. Save the SQL to your hard drive and open it in a text editor
  3. Search for the path of your old domain (i.e. thisismyurl.com) and replace it with your new domain (i.e. getawaygraphics.com) If you’re changing the path, (/blog/) to the root or something as well please make sure to search for the whole string!
  4. Search again! 
  5. Change your server paths. This is a UNIX friendly path that the server uses to identify where you are on that hard drive. For example it may look like /var/www/t/thisismy/public_html/. If you don’t know your server path use my phpinfo() plugin for WordPress to find it.

Installing WordPress on a new domain

Now that you’ve altered your SQL for your old WordPress website,

  1. Install a copy of WordPress on your new domain
  2. Open your phpMyAdmin or control panel and paste the edited SQL into your SQL query box
  3. Wait …
  4. Open your new website in a separate web browser. Assuming everything worked, you should be up and running.

One final note, I always like to re-save my permalink options at this point to ensure the server writes a proper .htaccess file as sometimes it seems to act up.

Search Engine Optimization for the new domain

Next, you’ll want to make sure that the search engines know that you’re new domain is the correct domain and that your old domain is no longer active. You can do this using what is called a 302 redirect. Pretty fancy right? Not really, we’re geeks but … it’s important and that’s where Matt’s post Switching things around comes in handy.

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.

Google Launches AdSense for Video Games

If you’re anything like me, you live for the latest round of web games but today, Google has taken the next step in the advertising front by introducing AdSense for Video Games

Do you develop or publish web-based games? If so, you’re contributing to a growing trend – according to comScore, over 25% of Internet users play online games every week, which is over 200 million users worldwide. As a beta user of AdSense for Games, you can display video ads, image ads, or text ads within your online games to earn revenue. You’ll be able to show these ads in placements you define, such as interstitial frames before a game, after a level change, or when a game is over. Members of our AdWords team will sell your in-game ad placements directly to top brand advertisers, and you’ll also see contextually targeted text and image ads based on content and demographic information. In addition, you’ll be able to control the ads you see on your pages using our filtering options.

Steven Hodson has a great article about it over on Mashable.