Manage Your Blog’s Content with Two Simple WordPress Hacks

Dec 13th, 09 by Jeff Orloff | View Comments |
You maybe interested in our latest article Personal Facebook Fan Pages of Celebrities.

It’s amazing that in my own non-scientific poll, half of those who work in some technology field still get the term hacker confused. A hacker is not someone who is leering in cyberspace ready to infiltrate their unsuspecting victim’s computer and pillage any information of use from its hard drive. A hacker is someone who looks for ways to manipulate things to make them work better. So when I speak of hacks for WordPress, I am looking at ways to change the code to make the application work better for us, not how to scrape content or steal log in information.

Hacks vs. Plug-ins

There are many different plug-ins available to help manage content on a WordPress blog so why would we want to mess with the code?

For starters, getting our hands dirty with the code of WordPress gives us a much better insight as to how the software works. As we become more comfortable with the source that powers our blog, we gain a better understanding of how to secure it from malicious attacks.

A second reason to avoid turning to a plug-in as a first resort is that an accumulation of plug-ins causes your blog to become bloated. Eventually, this bloat may begin to affect the way your blog loads and delivers to your audience.

Finally, if you pride yourself on going green or you just want to do what you can for the environment, you may be interested to know that code bloat can unnecessarily burden your server’s CPU. Making your server work harder uses more energy. Cooling a hard working CPU uses even more energy. Reducing code bloat saves energy.

Instead of relying on plug-ins, we are going to look at a few hacks that can help better manage a blog’s content. Each one of these hacks requires a bit of PHP knowledge and the ability to upload to your server.



Display a List of Future Posts

One of the most successful techniques television news uses is the teaser. Right before commercial break, they leak bits of information about upcoming stories to keep the viewers interested and glued to their television sets. You can do the same with your blog by letting your audience know about some of the upcoming posts that will soon be published displayed right in your blog’s sidebar.

  1. Create a new post but instead of posting it immediately, schedule it for another date.
  2. From your Dashboard, navigate to Appearance | Editor. From the list of files on the right hand side of your screen, select sidebar.php.
  3. Where ever you would like your future posts to appear, paste the following code:
    <?php query_posts('showposts=10&post_status=future'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <span><?php the_time('j. F Y'); ?></span></p>
    <?php endwhile;
    else: ?><p>No future events scheduled.</p>
    <?php endif; ?>
  4. Click on Update File.

Now your blog’s front page will display any future posts. There is one parameter, showposts, that you can change to the number you choose.

Tell Your Posts When to Expire

Just like any food in the cupboard, your posts might get stale after a little while. This next hack allows you to set an expiration date on your posts so that when the time comes, they leave your blog gracefully.

  1. Locate the WordPress loop that begins here:
    <php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    And ends here:

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  2. Replace your loop with the following code:
    <?php
    if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    $expirationtime = get_post_custom_values('expiration');
    if (is_array($expirationtime)) {
    $expirestring = implode($expirationtime);
    }
    $secondsbetween = strtotime($expirestring)-time();
    if ( $secondsbetween > 0 ) {
    // For example…
    the_title();
    the_excerpt();
    }
    endwhile;
    endif;
    ?>
  3. Save your changes.
  4. Write your post and from the custom fields, select the key expiration. Set the expiration date in the following format: mm/dd/yyyy 00:00:00.

Now, when your post hits the expiration date, it will be not be displayed in the loop, therefore, your audience will no longer see it.
In addition to trimming stale posts from your blog, this can be a great solution if you are running a contest and only want content posted for a short time, or if you are advertising a sale and want the related posts cleared from your blog when it is over.

We regularly update articles about resources, tutorials and Wordpress to help designers and developers. If you are new to WebDesignBooth, why not subscribe to our RSS feed and get the latest updates immediately. You can also subscribe through email or follow us on Twitter.
Jeff Orloff wrote this on behalf of Tophost.gr, a Greek web hosting company.
  • http://matthewlyle.com Matt

    Great tips. I think I’m going to use that first one as a custom widget in a new premium theme I’m working on. It’s a good idea.

  • http://www.bigthink.it/rubriche/il-meglio-della-settimana-43/ Il meglio della settimana #43 | BigThink

    [...] Manage your blog’s content with two simple WordPress hacks Come mostrare l’elenco con i futuri post e come impostare una data di scadenza per i tuoi post. [...]

  • http://GoHeadway.com Paul @ HeadwayTips

    Hah – sometimes the simplest answers are the best.

    These are two great tips. And I love that you don’t jump in to plugins etc.

    I like to get my hands dirty :-)

    Thanks,
    Paul.

  • http://www.afiffattouh.com/web-design/wordpress-usability-plugins-that-make-your-blog-more-visitor-friendly WordPress Usability: Plugins That Make Your Blog More Visitor Friendly | Afif Fattouh – Web Specialist

    [...] a recent post, We touted the benefits of hacking WordPress over the installation of plugins. One of these benefits is that plugins can cause your blog to [...]

  • http://www.bizimhost.biz/wordpress-usability-plugins-that-make-your-blog-more-visitor-friendly-2/ WordPress Usability: Plugins That Make Your Blog More Visitor Friendly | Bizimhost.biz

    [...] a recent post, We touted the benefits of hacking WordPress over the installation of plugins. One of these benefits is that plugins can cause your blog to [...]

  • http://www.webseorank.com/wordpress/wordpress-usability-plugins-that-make-your-blog-more-visitor-friendly.html CSS: WordPress Usability: Plugins That Make Your Blog More Visitor Friendly

    [...] a recent post, We touted the benefits of hacking WordPress over the installation of plugins. One of these benefits is that plugins can cause your blog to [...]

  • http://www.earinfectiontreatment.info Eleanor Simpson

    going green is always the best thing to do. it helps the environment a lot.;;;

  • http://www.watercoolerinfo.com Water Cooler :

    we should always Go Green to help the environment, always use products that are earth friendly”.*

  • http://www.trikemotorcycleslab.com Trike Motorcycles

    it is always a good idea to go green because we always want to help the environment :”~

  • http://www.premierpixels.com Las Vegas Web Design

     Thank you very much for sharing.

blog comments powered by Disqus