The term of Internal Linking Optimization means the placement of internal links from one pages of blog or website to another for transferring some more weight to most important pages of your blog. In fact, before making some external WordPress SEO optimization steps, you need to make good internal optimization and internal linking structure is one of the first steps you need to do.
I suppose that if you’re using WordPress, then your website is a blog and the main content of all blogs are blog-posts. This means that you need to give more weight to your posts. If you will have more links, internal and incoming links – you will get more traffic from search engines, especially from Google (read my previous article about How to add WordPress blog to Google). Usually all bloggers and webmasters are using widgets and plugins for internal linking (such as “Popular posts“, “Relative Posts” etc), but this is not enough, because some of the posts may not get in to this lists of links. In this case you need something like “Previous posts” WordPress hack.
Internal Linking Optimization of WordPress Blog Posts Without Plugins
“Ring Chain” internal linking structure
This WordPress hack will help you to create optimized ring “chain” internal linking structure of all your blog posts where absolutely all posts will be interlinked with each other without any plugins.
This is a scheme by which all your posts will be linked:

As you see on the scheme, all your WordPress posts will linked one by one and the last post will have link to the first post. For example, if you have 10 posts – first post will have 5 links to Post № 2,3,4,5,6 … second post will have links to Post № 3,4,5,6,7 … post № 6 will have links to Post № 7,8,9,10 and 1 – you will have ring of links, where all posts will have same number of incoming internal links. This method is really good for internal SEO optimization of your blog.
How to do this WordPress hack without a plugin
To show list of previous posts of your WordPress blog, you need to past the following code to your functions.php file (just in case, make a copy of functions.php):
<?php
/**
* Show list with previous posts.
*
* by Webdesignzo.com
*/
function webdesignzo_previous_posts ($post_num=5, $format = '', $list_tag='li', $echo=true){
global $post, $wpdb;
$sql ="SELECT ID, post_title, post_date, comment_count, guid
FROM $wpdb->posts p
WHERE ID < $post->ID
AND post_type = 'post'
AND post_status = 'publish'
ORDER BY ID DESC
LIMIT $post_num";
$res = $wpdb->get_results($sql);
$exclude = $post->ID;
foreach ($res as $id) $exclude .= ','.$id->ID;
$count_res = count($res);
if ( !$res || $count_res<$post_num ){
$post_num = $post_num-$count_res;
$sql2 ="SELECT ID, post_title, post_date, comment_count, guid
FROM $wpdb->posts p
WHERE ID NOT IN ($exclude)
AND post_type = 'post'
AND post_status = 'publish'
ORDER BY ID DESC
LIMIT $post_num";
$res2 = $wpdb->get_results($sql2);
$res = array_merge($res,$res2);
}
if (!$res) return false;
preg_match ('!\{date:(.*?)\}!',$format,$date_m);
foreach ($res as $pst){
$x == 'li1' ? $x = 'li2' : $x = 'li1';
$Title = $pst->post_title;
$a1 = "<a href='". get_permalink($pst->ID) ."' title='{$Title}'>";
$a2 = "</a>";
if ($format){
$date = apply_filters('the_time', mysql2date($date_m[1],$pst->post_date));
$Sformat = str_replace ($date_m[0], $date, $format);
$Sformat = str_replace('{title}', $Title, $Sformat);
$Sformat = str_replace('{a}', $a1, $Sformat);
$Sformat = str_replace('{/a}', $a2, $Sformat);
$Sformat = str_replace('{comments}', $pst->comment_count, $Sformat);
}
else $Sformat = $a1.$Title.$a2;
$out .= "\n<$list_tag class='$x'>{$Sformat}</$list_tag>";
}
if ($echo) echo $out;
else return $out;
}
?>
Update:
Your function.php file can be different (depends on your WordPress theme). If the last symbols of your function.php file are “?>“, then click right after ?>” and hit “Enter” to create a new line and put my code there, like on the screenshot below (click to enlarge):
?>“), then you should put my code in new line, but without < ?php at the beginning and ? > at the end... just use the code below instead of what I posted earlier:/**
* Show list with previous posts.
*
* by Webdesignzo.com
*/
function webdesignzo_previous_posts ($post_num=5, $format = '', $list_tag='li', $echo=true){
global $post, $wpdb;
$sql ="SELECT ID, post_title, post_date, comment_count, guid
FROM $wpdb->posts p
WHERE ID < $post->ID
AND post_type = 'post'
AND post_status = 'publish'
ORDER BY ID DESC
LIMIT $post_num";
$res = $wpdb->get_results($sql);
$exclude = $post->ID;
foreach ($res as $id) $exclude .= ','.$id->ID;
$count_res = count($res);
if ( !$res || $count_res<$post_num ){
$post_num = $post_num-$count_res;
$sql2 ="SELECT ID, post_title, post_date, comment_count, guid
FROM $wpdb->posts p
WHERE ID NOT IN ($exclude)
AND post_type = 'post'
AND post_status = 'publish'
ORDER BY ID DESC
LIMIT $post_num";
$res2 = $wpdb->get_results($sql2);
$res = array_merge($res,$res2);
}
if (!$res) return false;
preg_match ('!\{date:(.*?)\}!',$format,$date_m);
foreach ($res as $pst){
$x == 'li1' ? $x = 'li2' : $x = 'li1';
$Title = $pst->post_title;
$a1 = "<a href='". get_permalink($pst->ID) ."' title='{$Title}'>";
$a2 = "</a>";
if ($format){
$date = apply_filters('the_time', mysql2date($date_m[1],$pst->post_date));
$Sformat = str_replace ($date_m[0], $date, $format);
$Sformat = str_replace('{title}', $Title, $Sformat);
$Sformat = str_replace('{a}', $a1, $Sformat);
$Sformat = str_replace('{/a}', $a2, $Sformat);
$Sformat = str_replace('{comments}', $pst->comment_count, $Sformat);
}
else $Sformat = $a1.$Title.$a2;
$out .= "\n<$list_tag class='$x'>{$Sformat}</$list_tag>";
}
if ($echo) echo $out;
else return $out;
}
Save your functions.php file.
Now, to show list of previous posts, you just need to put next code into single.php (it can be different template file, it depends on your WordPress theme):
<ul> <h3>Previous posts:</h3> <?php webdesignzo_previous_posts (5); ?> </ul>
Update:
If you want to show the list of previous posts right after your article, then you need to put my code under this line in single.php: < ?php the_content(); ? >. See the screenshot below:
You can change the number of posts in the list by changing "5" to another digit and you can change "Previous posts" to your text. Also, you can change the look of the output by adding some CSS styles.
Optionally, you can add some additional information about posts (date and number of comments).
Example of code:
<ul>
<h3>Previous posts:</h3>
<?php webdesignzo_previous_posts (5, '{a}{title}{/a} (Comments: {comments}) | {date:j.M.Y}'); ?>
</ul>
You can see the example of working "Previous posts" WordPress hack at the end of each post on my blog (under "About author" section).
Later I will write a post about how to do the same Hack, but with filter for categories. This hack will show previous posts from current category.
This is only one of the existing methods of internal SEO optimization which you can use in combination with other tricks and WordPress plugins. Post your comments if you want to share some more tricks or if you have any questions about installation of this hack.







I am trying to do exactly as you explain above but i cannot get it work, is there any chance you could assist or help in any way?
Yes, I can help. Can you describe the problem?
My site appears with several lines of code across the top of it, squashing the existing graphics and layout.
Usually this happens when the code is incorrectly inserted to function.php file. You can send me a copy of your function.php and I will do that for you.
i have sent the functions.php file to your gmail address.
Previous post trick looks really neat & I think I will help in seo for sure, will try it on my blog.
Thanks
You are welcome!
I seem to be having the same problem as Martin. I tried placing the code at various locations throughout the file but the output’s always the same. Would you be willing to give a brief description of where the code should be placed in relation to the other code? Alternatively, are you aware of any plugin that accomplishes the same end? I’ve been searching around and can’t seem to find one. If you could do this I would be personally grateful and I’m sure everyone else experiencing the same issue (Martin and I can’t be the only ones) would greatly appreciate it as well. But anyway, thanks for the awesome tutorial. I’m sure once I figure it out it will be very helpful.
I’ve updated the description of the process (the code is also updated a little bit, to make it easy for you). I’ve solved the problem of Martin (he had encoded function.php file and he was inserting the code to the wrong place).
There is no such plugin to do the same trick, I’ve wrote this code because of that
I’d like to create one, but I never did this before.
Leave a comment, If there will be any problems with placing the code.
any way to add thumbnails to this? I’m monkeying around with adding the_post_thumbnail but it’s not behaving. rather than adding one thumb to each of (6 in my example) it adds six thumbs above the first .
I don’t know how to help you (yet), but I will try.
Hi there, great tutorial… where should I put my CSS? i want to change the color of the links? And how can i remove those dots like yours? thanks a lot…
How to show 5 previous posts only from the category of the post?
I love your knowledge and power with CODE, but can I just manually link to all my post in the manner you have shown in your diagram until I figure out how to utilize your coding? Your intellect is so far out there and so easy for you, that I will have to think on things for a while. However, keep it all coming, okay. I’ll catch on!
This is all pretty new to me, but I’m so excited to learn more every day…
Thanks,
Ralph
Great useful tutorials.Thank you.
Before reading this post I was only using related posts plugin but now I learn how to make better internal linking structure by showing previous posts.
Thanks Alex Joy for this great tutorial.
I think we all have benefitted from your code insertion so thanks, but there is obviously alot more to wordpress seo that just internal linking. Do you have any pages on this?