Advertise here

Top WordPress hack of all time

After a few years playing around with WordPress, I can’t exactly tell that I’ve growth, but WordPress has been a great blogging platform (some say a great CMS) that keeps updating. These updates normally ease the job of developer and web designer. However, when blogging trend changed into commerce-alike, bloggers tend to look for some functions that aren’t built in on WordPress. That is where hacks cames into play.

Commonly bloggers are looking for themes that has feature category on top, Twitter udpate list on site and etc. We have been developing some easy theme option with all our free themes and now here are what we did and hope it helps you too.

Feature category

Feature category
This is a tricky one. Since there are , it normally crashed with feature category code. Here are the code we used:

<?php
$tmp_query = $wp_query;
query_posts(‘showposts=1&cat=Feature));
if (have_posts()) : while (have_posts()) : the_post();
?>
<h1><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></h1>
<p><?php the_content(); ?></p>
<?php endwhile; endif; ?>

And these are the code for the normal update entries:

<?php
$wp_query = $tmp_query;
$odd = false;
if (have_posts()) : while (have_posts()) : the_post();
$odd = !$odd;
?>
<h1><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></h1>
<p><?php the_content(); ?></p>
<?php endwhile; ?>

While some looking for auto slider, next-previous button and etc effect. Just implement your JQuery, WordPress works with almost any scripting language :)

Footer widgetization

Widgetize footer
Commonly known as “widgetized sidebar”.

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Footer Widget’) ) : ?>
<!– Content when there’s no widget –>
<?php endif; ?>

However, you need to add a hook in functions.php. On functions.php (create one if you don’t have):

if ( function_exists(‘register_sidebar’) )
register_sidebar(array(
‘name’ => ‘Footer Widget’,
‘before_widget’ => ‘<div class=”footer-widget”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h3>’,
‘after_title’ => ‘</h3>’,
));

Twitter updates direct from twitter feeds

Twitter updates
This is the tricky part, also my favourite one.

<?php
$username = simplywp; // Your twitter username.
$prefix = “<p>”; // Prefix – some text / div you want displayed before your latest tweet.
$suffix = “</p>”; // Suffix – some text / div you want display after your latest tweet.
$feed = “http://search.twitter.com/search.atom?q=from:” . $username . “&rpp=1″;
function parse_feed($feed) {
$stepOne = explode(“<content type=\”html\”>”, $feed);
$stepTwo = explode(“</content>”, $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace(“<”, “<”, $tweet);
$tweet = str_replace(“>”, “>”, $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>

Remember to place styling on your Twitter updates.

Automatic entry’s thumbnail

Entries thumbnail
Exactly how simplyWP has it. However, we used a simple one instead of the TimThumb thumbnail resizer, it’s more a spontenous image resize. Here I’m going to show you how to auto resize your image without another php scripting hassle.

First, create a hook to call the very first image of your entry to be as the thumbnail in functions.php.

function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = “http://www.url.to/my_default_image.jpg”;
}
return $first_img;
}

Then, create a div to wrap the thumbnail. Code should be something like this:

<div class=”entry-thumbnail”><img src=”<?php echo catch_that_image() ?>” alt=”<?php echo urlencode(get_the_title($id)); ?>” /></div>

Then style it with:

.entry-thumbnail {
display: block;
width: 200px;
height: 180px;
float: left;
overflow: hidden;
}

.entry-thumbnail img {
width: 300px;
}

See that I force the img in the div to resize its width to fix into the wrap div.

Like it? Share it!

Digg it StumbleUpon del.icio.us Google Yahoo! reddit

More entries you might be interested in...

  •  
  •  
  •  
  •  
  •  
 

2 comments on Top WordPress hack of all time

  1. thanks for sharing. I think I might add some of this code to my blog. I usually like to edit all my themes on my own so this code of yours might give me some ideas that will take my blog even further.

  2. Andrew says:

    Hope you like it. Thanks for the visit :)

Advertisement
Follow Us