Langsung ke konten utama

Page Navigation With Arrow Keys In Blogger

Navigating between pages using the keyboard arrow keys is a very useful feature. It saves time scrolling down the page to find links to the next page in a site and is very intuitive for visitors.

In this tutorial, I offer a very simple Blogger template hack which can be used to navigate between newer and older posts on any page where the "blog pager" is present (including index, search, archive and item pages) using the left and right arrow keys.

Try out this functionality on my latest Blogger template release and read on for details of how to add this function to your own Blogger-based site.

There are two main steps to add arrow key navigation to our Blogger template:

  1. Edit the "Blog-Pager" element in the template HTML
  2. Add a simple script just before the closing </body> tag
Once we've added the relevant code, you'l be able to navigate to older posts and pages using the right arrow key, or to newer pages using the left arrow key.

Add the required code to your Blogger template

First we need to edit the "newer" and "older" links in the Blog-pager element of our Blogger template. 

Go to Template>Edit HTML in your Blogger dashboard and ensure you have checked the Expand widget templates box near the top of the page.

Using your browser's search function, locate the following section of code:
  <div class='blog-pager' id='blog-pager'>
    <b:if cond='data:newerPageUrl'>
      <span id='blog-pager-newer-link'>
      <a class='blog-pager-newer-link' expr:href='data:newerPageUrl' expr:id='data:widget.instanceId + &quot;_blog-pager-newer-link&quot;' expr:title='data:newerPageTitle'><data:newerPageTitle/></a>
      </span>
    </b:if>
    <b:if cond='data:olderPageUrl'>
      <span id='blog-pager-older-link'>
      <a class='blog-pager-older-link' expr:href='data:olderPageUrl' expr:id='data:widget.instanceId + &quot;_blog-pager-older-link&quot;' expr:title='data:olderPageTitle'><data:olderPageTitle/></a>
      </span>
    </b:if>

Edit the text highlighted in bold red so they appear like this instead:
  <div class='blog-pager' id='blog-pager'>
    <b:if cond='data:newerPageUrl'>
      <span id='blog-pager-newer-link'>
      <a class='blog-pager-newer-link' expr:href='data:newerPageUrl' expr:title='data:newerPageTitle' id='newer'><data:newerPageTitle/></a>
      </span>
    </b:if>
    <b:if cond='data:olderPageUrl'>
      <span id='blog-pager-older-link'>
      <a class='blog-pager-older-link' expr:href='data:olderPageUrl' expr:title='data:olderPageTitle' id='older'><data:olderPageTitle/></a>
      </span>
    </b:if>

The easiest way is to replace the code in your template with the replacement code above.

Next, locate the closing </body> tag in your template. Immediately before, paste the following section of code:
<script type='text/javascript'>
window.onload = function()
{
document.onkeyup = function(event)
{
var kGo = (!event) ? window.event : event;
switch(kGo.keyCode)
{
case 37:
window.location.href = document.getElementById(&#39;newer&#39;).href;
break;
case 39:
window.location.href = document.getElementById(&#39;older&#39;).href;
break;
}
};
};
</script>
At this point, it's advisable to preview your template. If you've made any errors when editing your code, this will be apparent in the preview. You can also test the new functionality by pressing the right arrow key while on the preview page.

If all is good, proceed to save your template and enjoy the keyboard shortcuts for navigating through your site.

You may want to let visitors know that they can navigate to newer/older posts using the arrow key as this is not a default feature of Blogger. For example, you could add a widget in your layout explaining the arrow key navigation.

What do you think?

I hope this quick tutorial was useful in helping you enable simple keyboard navigation between posts on your site. Please feel free to leave your thoughts and comments below.

Image credit: Woo Themes

Komentar

Postingan populer dari blog ini

Another Blog Is Already Hosted At This Address - How To Fix

When attempting to set up their Blogger custom domain, many Blogger users have received the following error message: Another blog is already hosted at this domain Although I have set up many custom domains to use with Blogger , until this weekend I had never experienced this issue for myself (and was unable to offer any definitive solution for those experiencing this problem). My friend was experiencing this very persoalan after setting up her new blog a few days ago. We have been able to find some solutions which I hope may help others who see this error message when attempting to set up their custom domain. Assuming you have already configured the DNS settings for your particular domain provider and have attempted to publish to a custom domain through your Blogger dashboard, here are the steps you should take: 1. Publish back to your Blog*Spot domain In order to make your blog accessible while troubleshooting your custom domain, it is advisable to publish back to your Blog*Spot...

Google Blogger For Dummies To Be Released In February!

If you're familiar with the "Dummies" series of books, you'll understand how helpful and insightful these textbooks can be in dealing with any subject. That being said, I'm happy to announce that Google Blogger for Dummies is due to hit bookshops on February 3rd. It's available to pre-order now from Amazon.com  (priced at $16.49) and will be available in Barnes and Noble, Waterstones and other bookshops, and also directly from Wiley. The author, Susan Gunelius, has been kind enough to send me a 60 page preview of this book, complete with a full and detailed table of contents and two sample chapters for my preliminary review. Also, when the book is released early next month, Susan has graciously offered me a copy of the book so that I can review it in it's entirety and offer readers my insights. What Google Blogger for Dummies will cover Being a "Dummies" guide, Google Blogger for Dummies will cover both the basics of using Blogger (crea...

Blogger Followers Now Integrated With Google Friend Connect

When Google Friend Connect was introduced a few months ago, it seemed inevitable that eventually this service would be closely integrated with Blogger to enable more social interaction around our blogs and social communities. Today the Blogger Buzz blog announced that Friend Connect has been integrated with the Followers feature , enabling readers to log in and become a follower of your blog using their preferred login details (rather than using only their Google account). As explained in the introductory post: [...] Your readers come from across the web, from Yahoo, AOL, WordPress, Typepad... not just Blogger. That's why we're excited to announce that we've integrated Blogger Following with Google Friend Connect. Friend Connect encourages readers to use one account (whether it's a Google account, a Yahoo, AIM or OpenID account) to follow any site - a Blogger blog, a WordPress blog, or any other site that has incorporated Friend Connect. This integration promis...