Add Page Number (with First and Last Page) Navigation Link for Blogger (Blogspot) with Gadget Element and Manual Hack
Blogger free blog publishing platform uses a pretty limited navigation features that only display “Older Posts” or “Newer Posts” link to let readers navigate and browse to other pages on homepage (index), archive, category and label pages. Unlike WordPress blog that supports plugin to customize the page navigation link to numbered pages listing to make it more user friendly, Blogger, whether hosted on blogspot.com or custom domain does not have such flexibility.
However, it’s still possible to change and replace the typical classic “Older Posts” and “Newer Posts” navigation link on Blogger blog to numbered pages navigation, as illustrated in figure below by using a CSS and JavaScript hack wrote by Mohamed Rias.

As shown in image above, a navigation link consists of page numbers, first page, last page, next page and previous page (when applicable) is display on Blogger blog instead of the usual “Older Items” and “Newer Items” text links.
To add the “new” navigation link with page number to Blogger blog, simply add in a new Page Element Gadget in the Blogger. To do so, follow the guide below:
- Login to Blogger account Dashboard.
- Click on the Layout link for the blog that you want to modify (if you’re viewing the blog and logged in to Blogger or Google Account, just click on Customize on the Next Blog toolbar.
- Go to Page Element tab (by default).
- Click on Add a Gadget anywhere in the layout.
- In the Add a Gadget window, select HTML/JavaScript.
- Add the following code into the Content text field. Title field can be left blank, or just type in any description such as “Page Navigation” to differentiate it from the rest of widgets.
<style>
.showpageArea {
padding: 0 2px;margin-top:10px;margin-bottom:10px;
}.showpageArea a {
border: 1px solid #505050;
color: #000000;font-weight:normal;
padding: 3px 6px !important;
padding: 1px 4px ;margin:0px 4px;
text-decoration: none;
}.showpageArea a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}.showpageNum a {
border: 1px solid #505050;
color: #000000;font-weight:normal;
padding: 3px 6px !important;
padding: 1px 4px ;margin:0px 4px;
text-decoration: none;
}.showpageNum a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;}
.showpagePoint {
font-size:11px;
padding: 2px 4px 2px 4px;
margin: 2px;
font-weight: bold;
border: 1px solid #333;
color: #fff;
background-color: #000000;
}.showpage a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}.showpageNum a:link,.showpage a:link {
font-size:11px;
padding: 2px 4px 2px 4px;
margin: 2px;
text-decoration: none;
border: 1px solid #0066cc;
color: #0066cc;
background-color: #FFFFFF;}.showpageNum a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}
</style><script type=”text/javascript”>
function showpageCount(json) {
var thisUrl = location.href;
var htmlMap = new Array();
var isFirstPage = thisUrl.substring(thisUrl.length-14,thisUrl.length)==”.blogspot.com/”;
var isLablePage = thisUrl.indexOf(“/search/label/”)!=-1;
var isPage = thisUrl.indexOf(“/search?updated”)!=-1;
var thisLable = isLablePage ? thisUrl.substr(thisUrl.indexOf(“/search/label/”)+14,thisUrl.length) : “”;
thisLable = thisLable.indexOf(“?”)!=-1 ? thisLable.substr(0,thisLable.indexOf(“?”)) : thisLable;
var thisNum = 1;
var postNum=1;
var itemCount = 0;
var fFlag = 0;
var eFlag = 0;
var html= ”;
var upPageHtml =”;
var downPageHtml =”;var pageCount=5;
var displayPageNum=3;
var firstPageWord = ‘First’;
var endPageWord = ‘Last’;
var upPageWord =’Previous’;
var downPageWord =’Next’;var labelHtml = ‘<span class=”showpageNum”><a href=”/search/label/’+thisLable+’?&max-results=’+pageCount+’”>’;
for(var i=0, post; post = json.feed.entry[i]; i++) {
var timestamp = post.published.$t.substr(0,10);
var title = post.title.$t;
if(isLablePage){
if(title!=”){
if(post.category){
for(var c=0, post_category; post_category = post.category[c]; c++) {
if(encodeURIComponent(post_category.term)==thisLable){
if(itemCount==0 || (itemCount % pageCount ==(pageCount-1))){
if(thisUrl.indexOf(timestamp)!=-1 ){
thisNum = postNum;
}postNum++;
htmlMap[htmlMap.length] = ‘/search/label/’+thisLable+’?updated-max=’+timestamp+’T00%3A00%3A00%2B08%3A00&max-results=’+pageCount;
}
}
}
}//end if(post.category){itemCount++;
}}else{
if(title!=”){
if(itemCount==0 || (itemCount % pageCount ==(pageCount-1))){
if(thisUrl.indexOf(timestamp)!=-1 ){
thisNum = postNum;
}if(title!=”) postNum++;
htmlMap[htmlMap.length] = ‘/search?updated-max=’+timestamp+’T00%3A00%3A00%2B08%3A00&max-results=’+pageCount;
}
}
itemCount++;
}
}for(var p =0;p< htmlMap.length;p++){
if(p>=(thisNum-displayPageNum-1) && p<(thisNum+displayPageNum)){
if(fFlag ==0 && p == thisNum-2){
if(thisNum==2){
if(isLablePage){
upPageHtml = labelHtml + upPageWord +’</a></span>’;
}else{
upPageHtml = ‘<span class=”showpage”><a href=”/”>’+ upPageWord +’</a></span>’;
}
}else{
upPageHtml = ‘<span class=”showpage”><a href=”‘+htmlMap[p]+’”>’+ upPageWord +’</a></span>’;
}fFlag++;
}if(p==(thisNum-1)){
html += ‘ <span class=”showpagePoint”><u>’+thisNum+’</u></span>’;
}else{
if(p==0){
if(isLablePage){
html = labelHtml+’1</a></span>’;
}else{
html += ‘<span class=”showpageNum”><a href=”/”>1</a></span>’;
}
}else{
html += ‘<span class=”showpageNum”><a href=”‘+htmlMap[p]+’”>’+ (p+1) +’ </a></span>’;
}
}if(eFlag ==0 && p == thisNum){
downPageHtml = ‘<span class=”showpage”> <a href=”‘+htmlMap[p]+’”>’+ downPageWord +’</a></span>’;
eFlag++;
}
}//end if(p>=(thisNum-displayPageNum-1) && p<(thisNum+displayPageNum)){
}//end for(var p =0;p< htmlMap.length;p++){if(thisNum>1){
if(!isLablePage){
html = ‘<span class=”showpage”><a href=”/”>’+ firstPageWord +’ </a></span>’+upPageHtml+’ ‘+html +’ ‘;
}else{
html = ”+labelHtml + firstPageWord +’ </a></span>’+upPageHtml+’ ‘+html +’ ‘;
}
}html = ‘<div class=”showpageArea”><span style=”font-size:11px;padding: 2px 4px 2px 4px;margin: 2px 2px 2px 2px;color: #000000;border: 1px solid #333; background-color: #FFFFFF;” class=”showpage”>Page ‘+thisNum+’ of ‘+(postNum-1)+’: </span>’+html;
if(thisNum<(postNum-1)){
html += downPageHtml;
html += ‘<span class=”showpage”><a href=”‘+htmlMap[htmlMap.length-1]+’”> ‘+endPageWord+’</a></span>’;
}if(postNum==1) postNum++;
html += ‘</div>’;if(isPage || isFirstPage || isLablePage){
var pageArea = document.getElementsByName(“pageArea”);
var blogPager = document.getElementById(“blog-pager”);if(postNum <= 2){
html =”;
}for(var p =0;p< pageArea.length;p++){
pageArea[p].innerHTML = html;
}if(pageArea&&pageArea.length>0){
html =”;
}if(blogPager){
blogPager.innerHTML = html;
}
}}
</script><script src=”/feeds/posts/summary?alt=json-in-script&callback=showpageCount&max-results=99999″ type=”text/javascript”></script>
- Click Save button.
- Drag and drop the newly added HTML/JavaScript gadget to directly right below the Blog Posts element.

- Click on Save button to make the change effective.
For user who don’t want to use the Page Element widget or gadget, it’s possible to manually editing the HTML file, although it’s more difficult to do and should only be tried by blogger with technical expertise.
- Login to Blogger account Dashboard.
- Click on the Layout link for the blog that you want to modify (if you’re viewing the blog and logged in to Blogger or Google Account, just click on Customize on the Next Blog toolbar.
- Go to Edit HTML tab (there is no need to expand widget templates).
- Search for the following line:
]]></b:skin> - Copy the following CSS code and paste or append the code above the line:
.showpageArea {
padding: 0 2px;margin-bottom:10px;margin-top:10px;
}.showpageArea a {
border: 1px solid #505050;
color: #000000;font-weight:normal;
padding: 3px 6px !important;
padding: 1px 4px ;margin:0px 4px;
text-decoration: none;
}.showpageArea a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}.showpageNum a {
border: 1px solid #505050;
color: #000000;font-weight:normal;
padding: 3px 6px !important;
padding: 1px 4px ;margin:0px 4px;
text-decoration: none;
}.showpageNum a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}.showpagePoint {
font-size:11px;
padding: 2px 4px 2px 4px;
margin: 2px;
font-weight: bold;
border: 1px solid #333;
color: #fff;
background-color: #000000;
}.showpage a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
}.showpageNum a:link,.showpage a:link {
font-size:11px;
padding: 2px 4px 2px 4px;
margin: 2px;
text-decoration: none;
border: 1px solid #0066cc;
color: #0066cc;
background-color: #FFFFFF;
}.showpageNum a:hover {
font-size:11px;
border: 1px solid #333;
color: #000000;
background-color: #FFFFFF;
} - Next, search for the following line of code in the template’s HTML code:
<b:section class='main' id='main' showaddelement='no'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'/>
</b:section>Note: The ‘no’ after “showaddelement” can be ‘yes’ for some bloggers.
- Add and append the following JavaScript code right after the </b:section> line:
<script type="text/javascript">
function showpageCount(json) {
var thisUrl = location.href;
var htmlMap = new Array();
var isFirstPage = thisUrl.substring(thisUrl.length-14,thisUrl.length)==".blogspot.com/";
var isLablePage = thisUrl.indexOf("/search/label/")!=-1;
var isPage = thisUrl.indexOf("/search?updated")!=-1;
var thisLable = isLablePage ? thisUrl.substr(thisUrl.indexOf("/search/label/")+14,thisUrl.length) : "";
thisLable = thisLable.indexOf("?")!=-1 ? thisLable.substr(0,thisLable.indexOf("?")) : thisLable;
var thisNum = 1;
var postNum=1;
var itemCount = 0;
var fFlag = 0;
var eFlag = 0;
var html= '';
var upPageHtml ='';
var downPageHtml ='';var pageCount=5;
var displayPageNum=3;
var firstPageWord = 'First';
var endPageWord = 'Last';
var upPageWord ='Previous';
var downPageWord ='Next';var labelHtml = '<span class="showpageNum"><a href="/search/label/'+thisLable+'?&max-results='+pageCount+'">';
for(var i=0, post; post = json.feed.entry[i]; i++) {
var timestamp = post.published.$t.substr(0,10);
var title = post.title.$t;
if(isLablePage){
if(title!=''){
if(post.category){
for(var c=0, post_category; post_category = post.category[c]; c++) {
if(encodeURIComponent(post_category.term)==thisLable){
if(itemCount==0 || (itemCount % pageCount ==(pageCount-1))){
if(thisUrl.indexOf(timestamp)!=-1 ){
thisNum = postNum;
}postNum++;
htmlMap[htmlMap.length] = '/search/label/'+thisLable+'?updated-max='+timestamp+'T00%3A00%3A00%2B08%3A00&max-results='+pageCount;
}
}
}
}//end if(post.category){itemCount++;
}}else{
if(title!=''){
if(itemCount==0 || (itemCount % pageCount ==(pageCount-1))){
if(thisUrl.indexOf(timestamp)!=-1 ){
thisNum = postNum;
}if(title!='') postNum++;
htmlMap[htmlMap.length] = '/search?updated-max='+timestamp+'T00%3A00%3A00%2B08%3A00&max-results='+pageCount;
}
}
itemCount++;
}
}for(var p =0;p< htmlMap.length;p++){
if(p>=(thisNum-displayPageNum-1) && p<(thisNum+displayPageNum)){
if(fFlag ==0 && p == thisNum-2){
if(thisNum==2){
if(isLablePage){
upPageHtml = labelHtml + upPageWord +'</a></span>';
}else{
upPageHtml = '<span class="showpage"><a href="/">'+ upPageWord +'</a></span>';
}
}else{
upPageHtml = '<span class="showpage"><a href="'+htmlMap[p]+'">'+ upPageWord +'</a></span>';
}fFlag++;
}if(p==(thisNum-1)){
html += '&nbsp;<span class="showpagePoint"><u>'+thisNum+'</u></span>';
}else{
if(p==0){
if(isLablePage){
html = labelHtml+'1</a></span>';
}else{
html += '<span class="showpageNum"><a href="/">1</a></span>';
}
}else{
html += '<span class="showpageNum"><a href="'+htmlMap[p]+'">'+ (p+1) +' </a></span>';
}
}if(eFlag ==0 && p == thisNum){
downPageHtml = '<span class="showpage"> <a href="'+htmlMap[p]+'">'+ downPageWord +'</a></span>';
eFlag++;
}
}//end if(p>=(thisNum-displayPageNum-1) && p<(thisNum+displayPageNum)){
}//end for(var p =0;p< htmlMap.length;p++){if(thisNum>1){
if(!isLablePage){
html = '<span class="showpage"><a href="/">'+ firstPageWord +' </a></span>'+upPageHtml+' '+html +' ';
}else{
html = ''+labelHtml + firstPageWord +' </a></span>'+upPageHtml+' '+html +' ';
}
}html = '<div class="showpageArea"><span style="font-size:11px;padding: 2px 4px 2px 4px;margin: 2px 2px 2px 2px;color: #000000;border: 1px solid #333; background-color: #FFFFFF;" class="showpage">Page '+thisNum+' of '+(postNum-1)+': </span>'+html;
if(thisNum<(postNum-1)){
html += downPageHtml;
html += '<span class="showpage"><a href="'+htmlMap[htmlMap.length-1]+'"> '+endPageWord+'</a></span>';
}if(postNum==1) postNum++;
html += '</div>';if(isPage || isFirstPage || isLablePage){
var pageArea = document.getElementsByName("pageArea");
var blogPager = document.getElementById("blog-pager");if(postNum <= 2){
html ='';
}for(var p =0;p< pageArea.length;p++){
pageArea[p].innerHTML = html;
}if(pageArea&&pageArea.length>0){
html ='';
}if(blogPager){
blogPager.innerHTML = html;
}
}}
</script><script src="/feeds/posts/summary?alt=json-in-script&callback=showpageCount&max-results=99999" type="text/javascript"></script>
- Click on Preview button to ensure that no code error been found. No effect on the navigation hack can be seen though.
- Click on Save Template to save the change.
Customization and Modification
- For user who is not using blogspot.com domain (using self-hosted domain name), modify the .blogspot.com and 14 (13 characters of domain name + 1) in the line of var isFirstPage = thisUrl.substring(thisUrl.length-14,thisUrl.length)==".blogspot.com/"; accordingly.
- The value in the line of var pageCount =5; determines the number of posts to be shown on each page.
- The value in the line of var displayPageNum = 3; defines the number of page links in the navigation bar to be displayed (e.g. 1 – 2 – 3).
- User who knows CSS and Java Script can customize the code to their likings.
Related Articles
- Workaround to Add Custom Channels into Blogger AdSense Page Element Widget
- How to Remove and Hide Blogger NavBar (Top Navigation Bar)
- google_ad_host Host ID in Google AdSense Ad Unit Code and Revenue Sharing
- Redirect Blogger RSS Feed to FeedBurner for Detailed Statistics and Monetize Ads
- Migrate and Switch to Blogger Beta: When’s Your Turn?
- Add and Insert to Put Google AdSense Ads Units Between Blog Posts in Blogger.com
- New Blogger with Category (Labels) and Instant Publishing Features plus New Templates
- How to Delete Blogger Blog
- Implement Ad Revenue Sharing in Blogger (Supports Google AdSense And Any Code)
- Blogger (at BlogSpot) with Category Labels and Drag-and-Drop Template Editing Out of Beta










































October 16th, 2009 21:59
doesnt work ;[
October 6th, 2009 11:53
Dear Sir/ Madam,
Could u tell me code how to display my blogpost like google page 1 2 3 4 5 6 7 8 9 10 after click next it show 11 12 13 14 15 16 17 18 19 20.
Could you help me?
my email: chantha_reksmy@yahoo.com
my website:http://ecambodia.blogspot.com
Regard,
Chantha
September 15th, 2009 23:45
no working dude
August 29th, 2009 14:30
It didn’t work for me. It’s not workin’
August 10th, 2009 03:30
Hello,
Can you help me. The page number doesnt seem to work. If you hit next it goes to page 3 and its not sorting the pages correctly at all I just noticed this now
August 10th, 2009 01:20
Thanks alot I got it working on my site.
July 26th, 2009 02:45
Thank you very much. your help is much effective
June 17th, 2009 03:04
oh happy happy its good
May 27th, 2009 15:05
I tried the gadget one but it didn’t work. What should I do??
April 11th, 2009 00:26
The code is working correctly and it leads to a far page when I clicked next page or page 2.
Please replay to this as shortly as possible.
Please!.
April 4th, 2009 16:46
This script not work in my blog. Please help me.
My Blog is Only Messages
February 14th, 2009 18:42
Yes,i agree with you guys…he is a cheater
For computer related tips & tricks,
Log onto:
Super Trickz
December 27th, 2008 23:27
fuck u i wasted my time taking this piece of shit n my advice to u better put some authenticated code next time ……..
looser
December 27th, 2008 02:06
yeah i have lost count of the number of site showing the same hacks..with slight modifications. well it doesnt work using page element. have tried the others in the edit html mode..no luck!
i must agree that since almost the entire hack was from somebody else, the credit given by you is only source1 and source2, at least have the decency to mention the original creator name or site and not just some obscure reference link which people wont notice.
are you that unwilling to do so?
anyway, when such a hack is shown..better to show example on blogspot also to show that you have urself also make it work and not just copy and pasting and making us think that you have make it work. another time
December 26th, 2008 05:59
You are a big looser. When you use others articles, you at least owe them a link back….
Using no follow link is stupidity imo!
December 26th, 2008 00:42
that code doesnt work.that shows only black colour
November 23rd, 2008 19:21
It’s a Leora Ka Bal solution.
November 22nd, 2008 05:49
Its not working for me, I copied the code above and I am using the new blogger. Could yoou please help me on this.
Ravi
November 21st, 2008 04:23
This doesnt work at all for me. Nothing changes at all.
November 15th, 2008 06:34
it’s work now on my Free cell phone theme!
but sometime, there,s an error like this
“No posts match your query.”
is there any solution!
November 15th, 2008 02:52
not work on my blogspot! may I wrong place the code?
November 13th, 2008 18:37
I’ve done now ………
page’s number are shown in my blog
but How to arrange pages in my blog ?
November 13th, 2008 18:10
not working …….
coz I did the same as u written above .
but no page numbering could be shown .
October 23rd, 2008 09:43
my blogs is still in classic blogger, could this treat i used to my blog?
And how to showing the page number on wordpress, the page number plugin just only support up to 2.5 version. is there any idea? or just waiting for plugin the new version release?
thanks!
October 19th, 2008 10:14
Everything OK. But while trying this found some problems. For example, when I click on ‘next’ page, some times it shows the same page, especially after 6th or 7th page. I think it is because of the script used. It is not as smooth as wordpress navigation – Jkwebtalks