Get the URL of the previous and next pages on the WordPress article page, and use the forward and backward keys on the keyboard to flip the pages.

Source: Internet
Author: User
Tags wordpress version

The Wordpress version I used is 3.4.1, And the template topic is inove developed by neotify. You can click here to download it. The reason why I want to get the address of the previous and next pages on the article page is to implement a function, the forward "->" and backward "<-" button of the keyboard is added to flip the page. This function is simple but practical, saving me the trouble of dragging the page to the bottom, next, click the next page. I will discuss the implementation steps below. Open the single. php file on the topic page and find the following content:

<div id="postnavi"><span class="prev"><?php next_post_link('%link') ?></span><span class="next"><?php previous_post_link('%link') ?></span><div class="fixed"></div></div>

Modify it:

<div id="postnavi"><span class="prev" id="prePage"><?php next_post_link('%link') ?></span><span class="next" id="nextPage"><?php previous_post_link('%link') ?></span><div class="fixed"></div></div>

Add the following JS at the end of the file:

<script language="javascript">document.onkeydown=gotoPage;var preUrl = document.getElementById("prePage").innerHTML.toLowerCase();var start = preUrl.indexOf('http');var end = preUrl.indexOf('" rel');preUrl = preUrl.substring(start,end);var nextUrl = document.getElementById("nextPage").innerHTML.toLowerCase();var start = nextUrl.indexOf('http');var end = nextUrl.indexOf('" rel');nextUrl = nextUrl.substring(start,end);function gotoPage(event) {event = event ? event : (window.event ? window.event : null);if (event.keyCode==37) {if (preUrl!=''){window.location=preUrl;}else{alert('This is already the first page."');}}if (event.keyCode==39) {if (nextUrl!=''){window.location=nextUrl;}else{alert('This is already the last page."');}}}</script>

OK. After the job is completed, the keyboard's forward and backward keys may be used to flip the page.

This article is from:Feng Libin's blog(Http://www.fenglibin.com), original address: http://www.fenglibin.com/get_pre_and_next_page_url_in_wordpress.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.