Page Navigation with WP-PageNavi style

  • Posted by M. Suleman Saeed Khan
  • at 12:38 AM -
  • 0 comments

page navi Blogger: Page Navigation with WP PageNavi style
If you use WordPress, you might have heard about WP-PageNavi, the famous page navigation plugin. But in Blogger (blogspot) there is no such “plugin”. Blogger provides only Previous Post, Next Post links, and they cannot satisfy us. In this post, I will show you some code to make beautiful page navigation with WP-PageNavi style.


This code is totally new and not based on any existing codes.

How to Install

1. Install CSS style

Open your template file, and file this line:
  1. ]]></b:skin>
Insert before it:
  1. /* Page Navigation */
  2. .pagenavi{clear:both;margin:10px auto;text-align:center}
  3. .pagenavi span,.pagenavi a{padding:3px;margin-right:5px;background:#fff;border:1px solid #c20c0c}
  4. .pagenavi a:visited{color:#c20c0c}
  5. .pagenavi a:hover,.pagenavi .current{background:#c20c0c;color:#fff;text-decoration:none}
  6. .pagenavi .pages,.pagenavi .current{font-weight:bold}
  7. .pagenavi .pages{border:none}
This style is red, which you can see at this blog. You might want to change some colors to fit your blog.

2. Install script

In your template file, find this line:
  1. <b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'>
Insert after it:
  1. <b:includable id='page-navi'>
  2. <div class="pagenavi">
  3. <script type="text/javascript">
  4. var pageNaviConf = {
  5. perPage: 5,
  6. numPages: 9,
  7. firstText: "First",
  8. lastText: "Last",
  9. nextText: "Next",
  10. prevText: "Prev"
  11. }
  12. </script>
  13. <script type="text/javascript" src="http://rilwis.googlecode.com/svn/trunk/blogger/pagenavi.min.js"></script>
  14. <div class="clear" />
  15. </div>
  16. </b:includable>

3. Insert page navigation into template

Final step is put the page navigation in right place where it is shown. In the template file, find the old page navigation with code:
  1. <!-- navigation -->
  2. <b:include name='nextprev'/>
Replace it with:
  1. <b:if cond='data:blog.pageType == "index"'>
  2. <b:include name='page-navi' />
  3. <b:else/>
  4. <b:if cond='data:blog.pageType == "archive"'>
  5. <b:include name='page-navi' />
  6. </b:if>
  7. </b:if>
If you can’t find the old page navigation code, then find this section of code:
  1. <b:section class='main' id='main' showaddelement='no'>
  2. <b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'>
  3. ...
  4. <b:includable id='main' var='top'>
  5. ...
  6. </b:includable>
  7. </b:widget>
  8. </b:section>
Insert this code immediately above the </b:includable> tag:
  1. <b:if cond='data:blog.pageType == "index"'>
  2. <b:include name='page-navi' />
  3. <b:else/>
  4. <b:if cond='data:blog.pageType == "archive"'>
  5. <b:include name='page-navi' />
  6. </b:if>
  7. </b:if>

Configuration

After installing, you might want to change some default settings. All the settings are in the script of second step above:
  1. var pageNaviConf = {
  2. perPage: 5,
  3. numPages: 9,
  4. firstText: "First",
  5. lastText: "Last",
  6. nextText: "Next",
  7. prevText: "Prev"
  8. }
As you can see, all parameters are has their own clear meanings:
- perPage: number of posts are shown in each page
- numPages: number of pages are shown in page navigation
- firstText, lastText, nextText, prevText: simply the “First”, “Last”, “Next”, “Prev” text
Comparing with other scritps of page navigation for Blogger, this script doesn’t force you to enter the blog URL. Besides that, you can see the code here is clean and easy for maintain.
Hope this hack will be useful for you. Thank you for reading. Feel free to leave any suggestion or thought in the comments.

Author

Written by Admin

Hi! I am M. Suleman Saeed Khan. I am trying to give you useful information. Thanks

0 comments: