Best 5 must have wordpress hacks
On March 31, 2010
WordPress is almost a super blogging tool right now we have, the main advantage of using wordpress is all about plugins and hacks. I have made list of 10 must have wordpress hacks for your blog. Download or Apply it free.
1. Avoid Duplicate Posts in Multiple Loops

- Let’s start by creating a simple PHP array, and put all post IDs from the first loop in it.
01<h2>Loop n°1</h2>0203<?php04$ids=array();05while(have_posts()) : the_post();06the_title();07?>08<br />0910<?php$ids[]=$post->ID;11endwhile; ?> - Now, the second loop: we use the PHP function
in_array()to check if a post ID is contained in the$idsarray. If the ID isn’t contained in the array, we can display the post because it wasn’t displayed in the first loop.1<h2>Loop n°2</h2>2<?php3query_posts("showposts=50");4while(have_posts()) : the_post();5if(!in_array($post->ID,$ids)) {6the_title();?>7<br />8<?php }9endwhile; ?>
2. Replacing “Next” and “Previous” Page Links with Pagination

- The first thing to do, obviously, is download the plug-in.
- Unzip the plug-in archive on your hard drive, and upload the wp-pagenavi.php and wp-pagenavi.css files to your theme directory.
- Open the file that you want the pagination to be displayed in (e.g. index.php, categories.php, search.php, etc.), and find the following code:
-
<div> <div><?php next_posts_link('Previous entries') ?></div> <div><?php previous_posts_link('Next entries') ?></div> </div>Replace this part with the code below:
1<?php2include('wp-pagenavi.php');3if(function_exists('wp_pagenavi')) { wp_pagenavi(); }4?> - Now we have to hack the plug-in file. To do so, open the wp-pagenavi.php file and find the following line (line #61):
1functionwp_pagenavi($before='',$after='') {2global$wpdb,$wp_query;We have to call the
pagenavi_init()function, so let’s do it this way:1functionwp_pagenavi($before='',$after='') {2global$wpdb,$wp_query;3pagenavi_init();//Calling the pagenavi_init() function - We’re almost done. The last thing to do is to add the wp-pagenavi style sheet to your blog. To do so, open up header.php and add the following line:
<link rel="stylesheet" href="<?php echo TEMPLATEPATH.'/pagenavi.css';?>" type="text/css" media="screen" />
3. Automatically Get Images on Post Content

- Paste the following code anywhere in your theme.
01<?phpif(have_posts()) : ?>02<?phpwhile(have_posts()) : the_post(); ?>0304<?php05$szPostContent=$post->post_content;06$szSearchPattern='~<img [^>]* />~';0708// Run preg_match_all to grab all the images and save the results in $aPics09preg_match_all($szSearchPattern,$szPostContent,$aPics);1011// Check to see if we have at least 1 image12$iNumberOfPics=count($aPics[0]);1314if($iNumberOfPics> 0 ) {15// Now here you would do whatever you need to do with the images16// For this example the images are just displayed17for($i=0;$i<$iNumberOfPics;$i++ ) {18echo$aPics[0][$i];19};20};2122endwhile;23endif;24?>
4. Display a Random Header Image on Your WordPress Blog

- Once you have selected some images to be your header images, name them 1.jpg, 2.jpg, 3.jpg and so on. You can use as many images as you want.
- Upload the images to your wp-content/themes/yourtheme/images directory.
- Open header.php and paste the following code in it:
- You’re done! Each page or post of your blog will now display a random header image.
5. Insert Ads (or Anything Else) in Your RSS Feed

Follow these simple steps to perform this hack:
- Edit the functions.php file of your theme. If your theme doesn’t have a functions.php file, simply create one.
- Paste the following code into your functions.php file:
1<?php2functioninsertAds($content) {3$content=$content.'<hr /><a href="http://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />';4return$content;5}6add_filter('the_excerpt_rss','insertAds');7add_filter('the_content_rss','insertAds');8?> - Save the file. You’re now displaying your ads in your RSS feed!
Special thanks to smashing magazine for this wonderful hacks
Waqar Hussain
a project management professional and blogger who write about project management and entrepreneurship in Pakistan
Website - Twitter - Facebook - More Posts
Join the mailing lists
Recent Stories
- Motivate your employees for more sucess
- Why we Pakistanis reach late at work?
- Why Pakistani entrepreneurs wait till disaster for fixing their business?
- Learn to say “NO” to your bosses
- Time management is the key to efficiency
- De-Variables a new entrepreneur from Pakistan
- Importance of Team in Project
- Workshop on “Arena Multimedia Specialist Pro”
- Why Ecommerce is essential for business in Pakistan?
- Why good feasibility report is required?
Facebook Fan Page
Twitter Feeds
- So far great parties for #EBS #GoLive 11 hrs ago
- Congratulation #TeamPakistan 1 day ago
- Innovation Pakistan looking for bloggers! Message me 1 day ago
- Hello all! Morning! Hows everyone at twitter? 1 day ago
- Any one have an idea about ptcl EVO 3.1 mbps service in North Karachi..... 4 days ago
- Yes! We are live with Oracle EBS R12 Supply Chain and Financial Modules! We seem junior & inexperience, but yet we have done GURU's work! 4 days ago
- I am not tweeting and it does not mean that I do not exists! :P 1 week ago
- Hello!!!!! No twitter for this month! no no no I am not protesting for #Aafia :p Stuck at office for work! :S 3 weeks ago
- RIP Arfa karim! We proud on you! 3 weeks ago
- RIP! Arfa karim! A little legend of Pakistan! We proud on u! 3 weeks ago
- More updates...
Posting tweet...












