dqy1265 2015-05-04 11:43
浏览 70

wordpress分页代码仅显示第一页

I want to apply pagination to my custom post type. Here is the pagination function I have used.

function roots_pagination($pages = '', $range = 2)
{  
     $showitems = ($range * 2)+1;  
     global $paged;
     if(empty($paged)) $paged = 1;
     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
            $pages = 1;
         }
     }   

    if(1 != $pages)
    {
        echo "<div class=\"pagination\">";
        echo "<ul><li><span>Page ".$paged." of ".$pages."</span></li>";
        if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo; First</a></li>";
        if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a></li>";

        for ($i=1; $i <= $pages; $i++)
        {
            if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
            {
                echo ($paged == $i)? "<li><a class=\"current\" href=\"#\">".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
            }
        }
        if ($paged < $pages && $showitems < $pages) echo "<li><a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a></li>";  
        if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>Last &raquo;</a></li>";
        echo "</ul></div>
";
    }
}

and here is the code i have used to call for pagination.

$paged = (get_query_var('paged'))?get_query_var('paged'):1;

//print_r($_SESSION);
//$paged = $_SESSION['paged'];
$temp=$wp_query;
$wp_query=null;
$wp_query=new Wp_Query();
$wp_query->query(array(
        'orderby'          => 'post_date',
        'order'            => 'DESC',
        'post_type'        => 'news',
        'post_status'      => 'publish',
        'posts_per_page'   => 4,
        'paged'=>$paged
)); 

global $wp_query;
//$temp=$wp_query;
$wp_query->in_the_loop=true;
while ($wp_query->have_posts() ) : the_post();
            //if($post_title !="27 Annual Convocation & Students Recognition Day"):
                $title = get_the_title();
    ?>
                <h4 style="border-top: medium double #dedcd2;">
                    <?php the_title();//echo $single_news->post_title; ?>
                </h4>
               <div class="text_exposed_root text_exposed" id="id_5485361e9d3362c15508684">
                    <p>
                        <?php echo substr(get_the_content(), 0, 250)."..."; //$single_news->post_content ?>
                        <a href="<?php the_permalink(); ?>"> View Details</a>
                    </p>
                </div>
<?php
endwhile;
roots_pagination();
?>

when i run this code it always display first page no matter If i click on page links. It creates page numbers fine but on clicking on links it display only first page. Any help please.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教