Category — Wordpress

Hotlink Protection – Protect Your Images Being Hotlink in Other Places

No people like their images of their blogs being hotlink in other places, because this will increase your bandwidth usage and slow down the speed of your blog. In order to avoid your images being hotlink by other people, you can use Hotlink Protection wordpress plugin to protect it.

How It Works

  • Referrer check if someone requests an image from your blog. If the referrer is not empty and not your blog the request is redirected to an information image
  • The image urls in the feed are replaced by an alternate url. This url is not protected by a referrer check so online feedreaders get the image

What It Not Does

  • It doesn’t protect the images in the feed. So hotlinking the image urls from the feed is possible. But in my opinion it is nearly impossible to protect this images without breaking some online feedreaders.
  • It doesn’t prevent someone from downloading your images and placing them on their own webspace

How to Display Google Adsense After The First Post

If you want to display Google Adsense After the first post, then you can refer to the following code and see how it works. Honestly, this is a wonderful code that I have been looking for so long.

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $loopcounter++; ?>

// the loop stuffs

<?php if ($loopcounter <= 1) { include (TEMPLATEPATH . '/ad.php'); } ?>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

Thanks Web Designer Wall for this awesome code.

How to Create Meta Description Function and Meta Keyword Tags

If you want to create meta description function and meta keyword tags for your wordpress themes, open header.php file and then copy and paste the following code within <head> and </head>.

<meta name="description" content="
<?php if ( (is_home()) || (is_front_page()) ) {
echo ('Your main description goes here');
} elseif(is_category()) {
echo category_description();
} elseif(is_tag()) {
echo '-tag archive page for this blog' . single_tag_title();
} elseif(is_month()) {
echo 'archive page for this blog'  . the_time('F, Y');
} else {
echo get_post_meta($post->ID, "Metadescription", true);

How to Solve “Error Establishing a Database Connection” for WordPress

Last week, I entered to one of my blogs and found that I get error message “error establishing a database connection”, my blog contents are disappeared due to database connection cannot be established.

I’m so curious and felt weird about this issue since I didn’t change any setting from my blog, I also didn’t change something in wp-config.php for the base configuration of the WordPress, how come I get the error message “error establishing a database connection”?

What I have Been Done After This

1. I double confirmed the info keyed in in wp-config.php file like  name of the database, username, password and local host. Hmm.. it is seems like nothing goes wrong!

2. I retrieved the backup copy from my email, create new database and give it a new database name,  import the backup copy to this new database and then make new configuration in wp-config.php file. (change database name and password only) is work!

Why It is work?

The backup copy is work, but the current database doesn’t work and show error establishing a database connection. Since the base configuration of the WordPress in wp-config.php doesn’t goes wrong, then I confirmed that there will be something wrong in my current database.

I guessed I need to repair all the tables in my current database, this can be done through phpMyAdmin. After repaired the database tables, my blog is back! It won’t show error message “error establishing database connection” anymore. That’s means my problem has been solved!

How to Display Recent Posts from Specific Category

Initially I was thinking to display all the posts from specific category in my archives page, but this doesn’t work well if you have thousand of posts for one category, that’s why I want to limit the number of recent posts displayed from specify category.

To display recent posts from specific category, you can make use of the following coding. To change the number of displayed recent posts, simply change the showposts=10 to your desired number; cat=1 is your category number, you have to change this too.

<?php $recent = new WP_Query("cat=1&amp;showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
<?php endwhile; ?>

In case you need to display all posts from specific category, then you can use the following coding. cat=6 is your category number, please change it.

<?php query_posts('cat=6'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $wp_query->is_home = false; ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> – <?php the_time('j F Y') ?></li>
<?php endwhile; endif; ?>

Thanks to Ready WP Themes for this coding.

How to Seperate Comments and Trackbacks

Most wordpress themes combine comments with trackbacks, if you want to separate comments and trackbacks so that it will looks more organized, then you can follow the below step by step guide.

Step 1

Open comments.php and look for

<?php foreach ($comments as $comment) : ?>

Paste after

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Step 2

Scroll down a bit and look for

<?php endforeach; /* end for each comment */ ?>

Paste before

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Step 3

Look for

<?php else : // this is displayed if there are no comments so far ?>

Paste before

<?php if ($trackback == true) { ?>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
<?php } ?>

How to Backup and Restore WordPress Database

Please keep in mind that you need to backup your wordpress database periodically to prevent your data lose in case of bad plugin installation or an attack by hacker. So do you know how to backup and restore your wordpress database? If you don’t, let me show you how.

DISCLAIMER: I will not going to hold responsible in any way should you encounter problems like loss of database and entire blog/website along the way. It worked excellently well for me.

How to Backup Your WordPress Database

1. Download and install WordPress Database Plugin and active this plugin.

2. In your wordpress dashboard, go to Tools > Backup

3. Under Backup Options, select “Download to your computer” and click on “Backup Now” button.

How to Restore Your WordPress Database

1. Log into your FTP account and delete everything in the /wp-content/cache directory.

2. Log into PHP MyAdmin and select your wordpress database.

3. A list of all of the tables contained in the database will be shown. Select all the tables and select the Drop option to delete them permanently.

4. After wordpress database is empty, it is time to upload your database by clicking Import tab.

5. Locate of the text file and then click “Go” button to import your wordpress database.

How to Display Most Recent Twitter Tweets in WordPress Blog

Since Twitter became popular, many bloggers like to display recent twitter tweets on their website or blog. To display most recent twitter tweets, simply copy and paste the following code to your sidebar.php file.

// Your twitter username.
$username = "TwitterUsername";
// Prefix - some text you want displayed before your latest tweet.
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix = "";
// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix = "";
$feed = "" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace(”&lt;”, “<”, $tweet);
$tweet = str_replace(”&gt;”, “>”, $tweet);
return $tweet;
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

Thanks the awesome code from WP Hacks.

Page 5 of 10« First...4567...Last »