WordPress的上一页/下一页链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress的上一页/下一页链接相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. /* prev/next links */
  3. if ($post->post_parent == 19) { /* 19 == id of 'Rooms' page */
  4. $exclude = implode(',',array('984'));
  5.  
  6. $toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude;
  7. $siblings = $toplevel.'&child_of='.$post->post_parent;
  8. if (function_exists(pause_exclude_pages)) {
  9. pause_exclude_pages();
  10. $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
  11. resume_exclude_pages();
  12. }
  13. else {
  14. $links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
  15. }
  16.  
  17. $links = array_filter(explode("</li>",$links));
  18.  
  19. foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } $links[$k] = $v.'</li>';}
  20.  
  21. $total = count($links)-1; $prev = (int)$current-1; $next = $current+1;
  22.  
  23. if ($current == $total) $next = '0'; // if you're on the last page, next will be the first
  24. if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last
  25.  
  26. $prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags
  27. $nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags
  28.  
  29. function change_anchor_text($link, $newtext, $placement) {
  30. $pos1 = strpos($link, '>')+1;
  31. $pos2 = strpos($link, '<', 1);
  32. $anchortext = substr($link, $pos1, $pos2-$pos1);
  33.  
  34. if($placement == 'before') {
  35. return str_replace($anchortext, $newtext.' '.$anchortext, $link);
  36. }
  37. else if ($placement == 'after') {
  38. return str_replace($anchortext, $anchortext.' '.$newtext, $link);
  39. }
  40. else if ($placement == 'replace') {
  41. return str_replace($anchortext, $newtext, $link);
  42. }
  43.  
  44. }
  45. $prevLinkb = $prevLink;
  46. $prevLink = change_anchor_text($prevLink, ' &lt; View Previous Room ', 'replace'); /* link customization goes here */
  47. $nextLink = change_anchor_text($nextLink, ' View Next Room &gt; ', 'replace');
  48. $prepend = '';
  49. $separator = '<a href="/lodging/" class="norm">Return to All Rooms</a>';
  50. $separator2 = '<a href="#" class="norm">Check Availability Online</a>';
  51.  
  52. echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.'</p>';
  53.  
  54. }
  55. /* end prev/next links */
  56. ?>

以上是关于WordPress的上一页/下一页链接的主要内容,如果未能解决你的问题,请参考以下文章

php WordPress |自定义上一页和下一页链接

WordPress的上一页/下一页链接

wordpress 如何在子页面中导航上一页和下一页

dedecms列表页单独上一页 下一页链接 适合手机版使用

织梦栏目列表页分页条获取上一页下一页链接

使用 Javascript 链接到下一页和上一页