我有一个页面ID数组,我需要用它来创建一个简单的下一页/上一页菜单。
下面你可以看到我到目前为止所做的一切。
我意识到我甚至不在这附近......
<?php
$pagelist = array(0,1358,226,1394,1402,1468,0);
$prevID = prev($pagelist);
$nextID = next($pagelist);
?>
<div class="navigation">
<?php if ($prevID != 0) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php } ?>
<?php if ($nextID != 0) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div><!-- .navigation -->
我认为我需要在某些时候使用当前页面ID,这是我使用此功能
<?php the_ID(); ?>
请问有人帮我指出正确的方向吗?
答案 0 :(得分:2)
假设您的网址包含id参数:
<?php
$pagelist = array(0,1358,226,1394,1402,1468,0);
$currentIndex = array_search($_GET['id'], $pagelist); // $_GET['id'] may be replace by your the_ID() function
$prevID = $currentIndex - 1 < 0 ? $pagelist[0] : $pagelist[$currentIndex - 1];
$nextID = $currentIndex + 1 > count($pagelist)-1 ? $pagelist[count($pagelist)-1] : $pagelist[$currentIndex + 1];
?>
<div class="navigation">
<?php if ($prevID != 0) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php } ?>
<?php if ($nextID != 0) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div><!-- .navigation -->
希望此解决方案可以帮助您