所有分类
  • 所有分类
  • 视频剪辑
广告位招租

七、制作分页和面包屑导航

在functions.php中添加:

分页代码:

//分页

function pagination($query_string){

global $posts_per_page, $paged;

$my_query = new WP_Query($query_string .”&posts_per_page=-1″);

$total_posts = $my_query->post_count;

if(empty($paged))$paged = 1;

$prev = $paged – 1;

$next = $paged + 1;

$range = 6; // 修改数字,可以显示更多的分页链接

$showitems = ($range * 2)+1;

$pages = ceil($total_posts/$posts_per_page);

if(1 != $pages){

echo “<div class=’pagination’>”;

echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? “<a href='”.get_pagenum_link(1).”‘>最前</a>”:””;

echo ($paged > 1 && $showitems < $pages)? “<a href='”.get_pagenum_link($prev).”‘>上一页</a>”:””;

for ($i=1; $i <= $pages; $i++){

if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){

echo ($paged == $i)? “<span class=’current’>”.$i.”</span>”:”<a href='”.get_pagenum_link($i).”‘ class=’inactive’ >”.$i.”</a>”;

}

}

echo ($paged < $pages && $showitems < $pages) ? “<a href='”.get_pagenum_link($next).”‘>下一页</a>” :””;

echo ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) ? “<a href='”.get_pagenum_link($pages).”‘>最后</a>”:””;

echo “</div>\n”;

}

}

 

在sytle.css下面添加

/** 翻页 **/

.navigation {   float:right;      width:700px;  margin: 5px 0 5px 0;      text-align:right;      }

.navigation_b {      float:right;      width:700px;  text-align:right;      }

.pagination {   line-height:25px;    }

.pagination span, .pagination a {    font-size:12px;       margin: 2px 6px 2px 0;  background:#fff;     border:1px solid #ccc;       color:#787878;       padding:2px 5px 2px 5px;     }

.pagination a:hover {     background: #0196E3;   border:1px solid #fff;     color:#fff;       }

.pagination .current {     background: #0196E3;   color:#fff;       font-size:12px;       padding:2px 5px 2px 5px;     }

 

使用方法:

<?php pagination($query_string); ?>

 

 

标题调用:

<?php wp_title(”);?>

 

面包屑导航调用:

<?php wheatv_breadcrumbs(); ?>

 

在functions.php中添加:

function wheatv_breadcrumbs() {

$delimiter = ‘ > ‘;

$name = ‘首页’; //

 

if ( !is_home() ||!is_front_page() || is_paged() ) {

 

global $post;

$home = get_bloginfo(‘url’);

echo ‘<a href=”‘ . $home . ‘”  class=”gray”>’ . $name . ‘</a> ‘ . $delimiter . ‘ ‘;

 

if ( is_category() ) {

global $wp_query;

$cat_obj = $wp_query->get_queried_object();

$thisCat = $cat_obj->term_id;

$thisCat = get_category($thisCat);

$parentCat = get_category($thisCat->parent);

if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ‘ ‘ . $delimiter . ‘ ‘));

echo single_cat_title();

 

} elseif ( is_day() ) {

echo ‘<a href=”‘ . get_year_link(get_the_time(‘Y’)) . ‘”  class=”gray”>’ . get_the_time(‘Y’) . ‘</a> ‘ . $delimiter . ‘ ‘;

echo ‘<a href=”‘ . get_month_link(get_the_time(‘Y’),get_the_time(‘m’)) . ‘”  class=”gray”>’ . get_the_time(‘F’) . ‘</a> ‘ . $delimiter . ‘ ‘;

echo get_the_time(‘d’);

 

} elseif ( is_month() ) {

echo ‘<a href=”‘ . get_year_link(get_the_time(‘Y’)) . ‘”  class=”gray”>’ . get_the_time(‘Y’) . ‘</a> ‘ . $delimiter . ‘ ‘;

echo get_the_time(‘F’);

 

} elseif ( is_year() ) {

echo get_the_time(‘Y’);

 

} elseif ( is_single() ) {

$cat = get_the_category(); $cat = $cat[0];

echo get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);

echo “正文”;

 

} elseif ( is_page()||!$post->post_parent ) {

the_title();

 

} elseif ( is_page()||$post->post_parent ) {

$parent_id  = $post->post_parent;

$breadcrumbs = array();

while ($parent_id) {

$page = get_page($parent_id);

$breadcrumbs[] = ‘<a href=”http://www.wheatv.com/site/wp-admin/ . get_permalink($page->ID) . ”  class=”gray”>’ . get_the_title($page->ID) . ‘</a>’;

$parent_id  = $page->post_parent;

}

$breadcrumbs = array_reverse($breadcrumbs);

foreach ($breadcrumbs as $crumb) echo $crumb . ‘ ‘ . $delimiter . ‘ ‘;

the_title();

 

} elseif ( is_search() ) {

echo get_search_query();

 

} elseif ( is_tag() ) {

echo single_tag_title();

 

} elseif ( is_author() ) {

global $author;

$userdata = get_userdata($author);

echo ‘由’.$userdata->display_name.’发表’;

 

} elseif ( is_404() ) {

echo ‘404 错误’;

}

 

if ( get_query_var(‘paged’) ) {

if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘ (‘;

echo ‘第’ . ‘ ‘ . get_query_var(‘paged’).’ 页’;

if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘)’;

}

}else{

echo $name;

}

}

资源下载
客服QQ:822511134
资源下载
客服QQ:822511134

原文链接:https://i.haogew.cn/192.html,转载请注明出处~~~

0
广告位招租

评论0

广告位招租
疫情期间优惠活动!原299包年VIP,现99;原399终身VIP,现199。随着资源不断增多,随时提价!立即查看
显示验证码
没有账号? 注册  忘记密码?