wordpress分页调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//页码/分页/翻页效果
function wp_pagenavi() {
//先申明两个全局变量
global $wp_query,$wp_rewrite;
//判断当前页面
$wp_query->query_vars['paged'] > 1 ?$current=$wp_query->query_vars['paged'] :$current= 1;
$pagination=array(
'base'=> @add_query_arg('paged','%#%'),
'format'=>'',
'total'=>$wp_query->max_num_pages,
'current'=>$current,
'show_all'=> false,
'type'=>'plain',
'end_size'=>'1',//在最后和最前至少显示多少个页码数,这里最后最前至少显示“1” 页的意思
'mid_size'=>'4',//在最后和最前之间至少显示多少个页码数
'prev_text'=>'上一页',
'next_text'=>'下一页'
);
if($wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) .'page/%#%/','paged');
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] =array('s'=>get_query_var('s'));
echo paginate_links($pagination);
}

<?php wp_pagenavi();?>

创建菜单和添加链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
register_nav_menus(array(
'primary' => '主导航',
'link_menu' => '友情链接',
'main_nav' => '分类页面二级导航',
'cate_link' => '分类友情链接',
));

wp_nav_menu(array(
'theme_location'=>'primary',
'container'=>'div',
'container_id'=>'nav',
'container_class'=>'nav',
'menu_class'=>'nav_content',
'menu_id'=>'nav_content'
)
);