之前给自己的首页文章改成了现在的分页,默认的分页翻起来挺不便的。然后想用同样的方法把自己的微博页也改成类似
分页,由于该页经常发一些论坛注册信息,所以写的条数比较多,不得而为之。可是用同样的方法,虽然改了函数,运行
没问题,就是当前页显示错误,一直停在第一页。今天又参照wp-commentnavi插件的源码,找关键的函数,把
- $paged = intval(get_query_var('cpage'));
加进代码,结果测试成功~现在代码变为
- function par_commentnavi($range = 9){
- // $paged - number of the current page
- global $paged, $wp_query;
- // How much pages do we have?
- $paged = intval(get_query_var('cpage'));
- if ( !$max_page ) {
- $max_page = $wp_query->max_num_comment_pages;
- }
- // We need the pagination only if there are more than 1 page
- if($max_page > 1){
- if(!$paged){
- $paged = 1;
- }
- // On the first page, don't put the First page link
- if($paged != 1){
- echo "<a class="extend" title="跳转到首页" href="" . get_comments_pagenum_link(1) . ""> 返回首页 </a>";
- }
- // To the previous page
- previous_comments_link(' « ');
- // We need the sliding effect only if there are more pages than is the sliding range
- if($max_page > $range){
- // When closer to the beginning
- if($paged < $range){
- for($i = 1; $i <= ($range + 1); $i++){
- echo "<a class="current" href="" . get_comments_pagenum_link($i) ."">$i</a>";
- }
- }
- // When closer to the end
- elseif($paged >= ($max_page - ceil(($range/2)))){
- for($i = $max_page - $range; $i <= $max_page; $i++){
- echo "<a class="current" href="" . get_comments_pagenum_link($i) ."">$i</a>";
- }
- }
- // Somewhere in the middle
- elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
- for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){
- echo "<a class="current" href="" . get_comments_pagenum_link($i) ."">$i</a>";
- }
- }
- }
- // Less pages than the range, no sliding effect needed
- else{
- for($i = 1; $i <= $max_page; $i++){
- echo "<a class="current" href="" . get_comments_pagenum_link($i) ."">$i</a>";
- }
- }
- // Next page
- next_comments_link(' » ');
- // On the last page, don't put the Last page link
- if($paged != $max_page){
- echo "<a class="extend" title="跳转到最后一页" href="" . get_comments_pagenum_link($max_page) . ""> 最后一页 </a>";
- }
- }
- }
参照的是无需wordpress分页插件, 为WordPress制作个性分页导航 不过先在还有个问题,我想让微博首页显示满唠叨,
而不是显示余数,不知哪位有高见可留言告知,非常感谢。
不错。。整需要!
[回复]
不错的代码,可以加入试试!路过宝地,露个小脸,呵呵。
[回复]
我还是用插件吧
[回复]
Danfi 回复:
2010-12-23 20:26
嗯,还是插件稳妥点,我现在改得都不想想升级了,不知道那些文件有没有更新的。
[回复]
ShowsCAI 回复:
2010-12-23 23:22
每次换主题的时候改的好痛苦。。。。
[回复]
确实不喜欢这个留言
[回复]
正好我刚好需要这个代码,能排成倒序最好。
[回复]
Danfi 回复:
2010-08-12 00:01
详细方法在链接那个页面,我只是改了function中的代码,倒序可以在后台那里设置的
[回复]