Wordpress Page Pagination IF查询
Wordpress Page Pagination IF query
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div id="page_nav">
<div class="wrapper">
<a href="<?php echo get_permalink($prevID); ?>"><i class="fa fa-arrow-left"></i>Previous Work</a><span>/</span>
<a id="back_link" href="http://kyleskelly.co.uk/#projects_container">Back to Projects</a><span>/</span>
<a href="<?php echo get_permalink($nextID); ?>">Next Work<i class="fa fa-arrow-right"></i></a>
</div>
</div>
我对 php 的了解不多,如有任何帮助将不胜感激,谢谢!
我要我的代码查询-
IF 是投资组合中的第一页,然后上一页 link 的标签无效。
else if 投资组合中的最后一页然后下一页 link 处于非活动状态。
else 我已有的代码
我还没有尝试过这段代码,但我认为它应该可以工作。如果有什么事情发生,请告诉我。我对代码进行了评论,或多或少地向您解释了我所做的事情。
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$current = get_the_ID();// Current Page ID. I assume IDs are unique, and all pages have one. All the IDs are in $pagelist.
$next = $prev = FALSE;
reset($pagelist);// Pointer to first element.
while ($page = current($pagelist) ){// Loop through the array. I used while instead of foreach for its convenience to get next element.
if( $page->ID == $current) {
$obj = next($pagelist);
$next = $obj ? $obj->ID : FALSE;// If there's a next, get the ID, otherwise we are the last page.
break;
}
$prev = $page->ID;// Previous element
next($pagelist);// Update pointer
}
?>
<div id="page_nav">
<div class="wrapper">
<?php if($prev !== FALSE) {// If I have a previous element, print out a ?>
<a href="<?php echo get_permalink($prev); ?>"><i class="fa fa-arrow-left"></i>Previous Work</a><span>/</span>
<?php } ?>
<a id="back_link" href="http://kyleskelly.co.uk/#projects_container">Back to Projects</a><span>/</span>
<?php if($next !== FALSE) {// If I have a next element, print out a ?>
<a href="<?php echo get_permalink($next); ?>">Next Work<i class="fa fa-arrow-right"></i></a>
<?php } ?>
</div>
</div>
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<div id="page_nav">
<div class="wrapper">
<a href="<?php echo get_permalink($prevID); ?>"><i class="fa fa-arrow-left"></i>Previous Work</a><span>/</span>
<a id="back_link" href="http://kyleskelly.co.uk/#projects_container">Back to Projects</a><span>/</span>
<a href="<?php echo get_permalink($nextID); ?>">Next Work<i class="fa fa-arrow-right"></i></a>
</div>
</div>
我对 php 的了解不多,如有任何帮助将不胜感激,谢谢!
我要我的代码查询-
IF 是投资组合中的第一页,然后上一页 link 的标签无效。
else if 投资组合中的最后一页然后下一页 link 处于非活动状态。
else 我已有的代码
我还没有尝试过这段代码,但我认为它应该可以工作。如果有什么事情发生,请告诉我。我对代码进行了评论,或多或少地向您解释了我所做的事情。
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$current = get_the_ID();// Current Page ID. I assume IDs are unique, and all pages have one. All the IDs are in $pagelist.
$next = $prev = FALSE;
reset($pagelist);// Pointer to first element.
while ($page = current($pagelist) ){// Loop through the array. I used while instead of foreach for its convenience to get next element.
if( $page->ID == $current) {
$obj = next($pagelist);
$next = $obj ? $obj->ID : FALSE;// If there's a next, get the ID, otherwise we are the last page.
break;
}
$prev = $page->ID;// Previous element
next($pagelist);// Update pointer
}
?>
<div id="page_nav">
<div class="wrapper">
<?php if($prev !== FALSE) {// If I have a previous element, print out a ?>
<a href="<?php echo get_permalink($prev); ?>"><i class="fa fa-arrow-left"></i>Previous Work</a><span>/</span>
<?php } ?>
<a id="back_link" href="http://kyleskelly.co.uk/#projects_container">Back to Projects</a><span>/</span>
<?php if($next !== FALSE) {// If I have a next element, print out a ?>
<a href="<?php echo get_permalink($next); ?>">Next Work<i class="fa fa-arrow-right"></i></a>
<?php } ?>
</div>
</div>