PHP WordPress的上一页/下一页链接
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP WordPress的上一页/下一页链接相关的知识,希望对你有一定的参考价值。
<?php
/* prev/next links */
if ($post->post_parent == 19) { /* 19 == id of 'Rooms' page */
$exclude = implode(',',array('984'));
$toplevel = 'title_li=&depth=1&echo=0&exclude='.$exclude;
$siblings = $toplevel.'&child_of='.$post->post_parent;
if (function_exists(pause_exclude_pages)) {
pause_exclude_pages();
$links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
resume_exclude_pages();
}
else {
$links = ($post->post_parent) ? wp_list_pages($siblings) : wp_list_pages($toplevel);
}
$links = array_filter(explode("</li>",$links));
foreach($links as $k=>$v) { if (strpos($v,'current_page_item') !== FALSE) { $current = $k; } $links[$k] = $v.'</li>';}
$total = count($links)-1; $prev = (int)$current-1; $next = $current+1;
if ($current == $total) $next = '0'; // if you're on the last page, next will be the first
if ($current == '0') $prev = $total; // if you're on the first page, prev will be the last
$prevLink = strip_tags($links[$prev],'<a>'); //remove the <li> tags
$nextLink = strip_tags($links[$next],'<a>'); //remove the <li> tags
function change_anchor_text($link, $newtext, $placement) {
$pos1 = strpos($link, '>')+1;
$pos2 = strpos($link, '<', 1);
$anchortext = substr($link, $pos1, $pos2-$pos1);
if($placement == 'before') {
return str_replace($anchortext, $newtext.' '.$anchortext, $link);
}
else if ($placement == 'after') {
return str_replace($anchortext, $anchortext.' '.$newtext, $link);
}
else if ($placement == 'replace') {
return str_replace($anchortext, $newtext, $link);
}
}
$prevLinkb = $prevLink;
$prevLink = change_anchor_text($prevLink, ' &lt; View Previous Room ', 'replace'); /* link customization goes here */
$nextLink = change_anchor_text($nextLink, ' View Next Room &gt; ', 'replace');
$prepend = '';
$separator = '<a href="/lodging/" class="norm">Return to All Rooms</a>';
$separator2 = '<a href="#" class="norm">Check Availability Online</a>';
echo '<p class="pnpn">'.$prepend.$prevLink.$separator.$nextLink.'</p>';
}
/* end prev/next links */
?>
以上是关于PHP WordPress的上一页/下一页链接的主要内容,如果未能解决你的问题,请参考以下文章
WordPress的上一页/下一页链接
WordPress - 如何将锚点添加到上一页/下一页链接
wordpress 如何在子页面中导航上一页和下一页
php网页上一页下一页翻页
dedecms列表页单独上一页 下一页链接 适合手机版使用
php 下一页/上一页