2012-10-19 58 views
0

我有一个页面ID的数组,我需要用它来创建一个简单的下一个/上一个页面菜单。页面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(); ?> 

可能有人请帮助我指出正确的方向吗?

回答

2

假设你的URL包含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 --> 

希望这个解决方案可以帮助你

+0

感谢您简单的解决方案! –

相关问题