wordpress 翻页代码
本例不使用插件。效果图如下:
需要修改的相关模板文件:
functions.php
style.css
index.php
/*翻页导航*/ .vt_nav { padding: 20px 0;; text-align: center;; font-size: 13px;; line-height: 18px; } .vt_nav .page-numbers,.vt_nav .dots:hover,.vt_nav .pages:hover { border: 1px solid #eee;; text-decoration: none;; background: #5080D8;; color: #fff;; text-shadow: 0px -1px rgba(0, 0, 0, 0.2);; display: inline-block;; margin: 2px;; padding: 1px;; padding: 4px 9px; } .vt_nav .current,.vt_nav .current:hover,.vt_nav a.page-numbers:hover { text-decoration: none;; background: #f9f9f9;; color: #5080D8; } .vt_nav .pages,.vt_nav .pages:hover { vertical-align: middle;; color: #CCC;; width: 120px; }functions.php中添加函数:
function vt_nav() { 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, '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 '<div class="vt_nav"><span class="page-numbers">' . $pagination[current] . ' / ' . $pagination[total] . '' . paginate_links($pagination) . ' '; }在index.php中恰当位置调用分页函数即可:
if(function_exists('vt_nav')) {vt_nav(); }