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 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 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) { ?>
<h3>Trackbacks</h3>
<ol>
<?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; ?>
</ol>
<?php } ?>

How to Display Most Popular Posts Without a WordPress Plugin

Many blogs have display most popular posts on their blog to make visitors stay longer on their posts, this is one of the way to attract more visitors to your blog. We actually can install a wordpress popular posts plugin to display our most popular posts, but if you don’t want to use plugin, you can simply hack your wordpress theme to do it manually.

Copy and paste the following code to the sidebar.php file, if you want to change the number of displayed posts, simply change the “5″ to your desired number.

<h2>Popular Posts</h2>
<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

Please note that the 5 most popular posts displayed is basing on the 5 most commented posts .