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