我以前也遇到了這個(gè)種問(wèn)題 糾結(jié)了好長(zhǎng)時(shí)間搞不好,最后找到了一種不用插件實(shí)現(xiàn)分頁(yè)的功能
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供甘南網(wǎng)站建設(shè)、甘南做網(wǎng)站、甘南網(wǎng)站設(shè)計(jì)、甘南網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、甘南企業(yè)網(wǎng)站模板建站服務(wù),10多年甘南做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
具體實(shí)現(xiàn)方法:
首先將下面一段函數(shù)代碼添加到主題的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 = 2; // only edit this if you want to show more page-links
$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)."'上一頁(yè)/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)."'下一頁(yè)/a" :"";
echo ($paged $pages-1 $paged+$range-1 $pages $showitems $pages) ? "a href='".get_pagenum_link($pages)."'最后/a":"";
echo "/div\n";
}
}
接下來(lái)用下面的代碼替換原來(lái)模板中默認(rèn)翻頁(yè)代碼或分頁(yè)插件代碼:
?php pagination($query_string); ?
最后再把下面的樣式代碼添加到style.css中,刷新一下頁(yè)面,與使用插件實(shí)現(xiàn)的翻頁(yè)效果一樣。
.pagination{
line-height:23px;
}
.pagination span, .pagination a{
font-size:12px;
margin: 2px 6px 2px 0;
background:#fff;
border:1px solid #e5e5e5;
color:#787878;
padding:2px 5px 2px 5px;
text-decoration:none;
}
.pagination a:hover{
background: #8391A7;
border:1px solid #fff;
color:#fff;
}
.pagination .current{
background: #fff;
border:1px solid #8d8d8d;
color:#393939;
font-size:12px;
padding:2px 5px 2px 5px;
}
有不明白的給我留言
不是!這是Doutzen Kroes
你發(fā)的這張圖就是這組里的其中一張!好像是2009給維多利亞的秘密拍的廣告
;imgurl=;imgrefurl=;usg=___kiZzcMnABvCY_zwQ6uxulZC2t4=h=1200w=1800sz=227hl=zh-CNum=1itbs=1tbnid=T8Hq_-odBbpLmM:tbnh=100tbnw=150prev=/images%3Fq%3DDoutzen%2BKroes%26ndsp%3D21%26hl%3Dzh-CN%26rlz%3D1C1GPCK_enCN360CN360%26sa%3DN%26start%3D273%26um%3D1%26newwindow%3D1ndsp=21rlz=1C1GPCK_enCN360CN360sa=Nstart=279um=1newwindow=1#tbnid=T8Hq_-odBbpLmMstart=282
這個(gè)問(wèn)題確實(shí)有點(diǎn)難度,評(píng)論這塊現(xiàn)在也弄得少,基本都用第三方的了。
按您的要求,除administrator外,都是注冊(cè)用戶,所以可以在當(dāng)前皮膚的functions.php中做如下判斷:
1
2
3
if ( ! is_super_admin() ){//非管理員
//blablabla...
}
然后將待審、垃圾評(píng)論、已回收的評(píng)論信息不顯示。這可以對(duì)get_comments函數(shù)提供的pre_get_comments鉤子進(jìn)行設(shè)置,比如:
1
2
3
4
5
add_action( 'pre_get_comments', 'dit_ha href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y1rHb3njcYP1ndnWbsmWTd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPjbdrH03Pjbknj0YPWm3PjfY" target="_blank" class="baidu-highlight"id/ae_some_comments', 999 );
function dit_ha href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y1rHb3njcYP1ndnWbsmWTd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPjbdrH03Pjbknj0YPWm3PjfY" target="_blank" class="baidu-highlight"id/ae_some_comments( $comments ){
$comments-query_vars['status'] = 'approve'; //獲取評(píng)論信息時(shí)只顯示已審核批準(zhǔn)的。
return $comments;
}
這時(shí)如果注冊(cè)用戶查看回收站時(shí),又要只能顯示當(dāng)前用戶自己的。所以還要增加點(diǎn)判斷
1
2
3
4
5
6
7
8
9
10
function dit_ha href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y1rHb3njcYP1ndnWbsmWTd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPjbdrH03Pjbknj0YPWm3PjfY" target="_blank" class="baidu-highlight"id/ae_some_comments( $comments ){
$status = $comments-query_vars['status'];
if ( 'trash' == $status ) {//當(dāng)用戶選擇顯示回收站時(shí),將ID添加進(jìn)篩選條件
global $current_user;
$comments-query_vars['user_id'] = $current_user-ID;
}else {
$comments-query_vars['status'] = 'approve'; //獲取評(píng)論信息時(shí)只顯示已審核批準(zhǔn)的。
}
return $comments;
}
所以,最后放在functions.php中的代碼片段整合如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
if ( ! is_super_admin() ){//非管理員
add_action( 'pre_get_comments', 'dit_hide_some_comments', 999 );
function dit_hide_some_comments( $comments ){
$status = $comments-query_vars['status'];
if ( 'trash' == $status ) {//當(dāng)用戶選擇顯示回收站時(shí),將ID添加進(jìn)篩選條件
global $current_user;
$comments-query_vars['user_id'] = $current_user-ID;
}else {
$comments-query_vars['status'] = 'approve'; //獲取評(píng)論信息時(shí)只顯示已審核批準(zhǔn)的。
}
return $comments;
}
}
先判斷下是否登錄,然后獲取當(dāng)前用戶對(duì)象,然后獲取當(dāng)前用戶對(duì)象的信息,需要哪些用哪些:
一般可以獲知當(dāng)前用戶的:'Username: ' 'User email: ' 'User first name: ''User last name: ''User display name: '
依次是:用戶名,用戶郵箱,用戶姓氏,用戶名字,顯示的名字
if(is_user_logged_in()){
$current_user = wp_get_current_user();
/**
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
* return;
*/
echo 'Username: ' . $current_user-user_login . 'br /';
echo 'User email: ' . $current_user-user_email . 'br /';
echo 'User first name: ' . $current_user-user_firstname . 'br /';
echo 'User last name: ' . $current_user-user_lastname . 'br /';
echo 'User display name: ' . $current_user-display_name . 'br /';
echo 'User a href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uhfdnHNBryu-uy7hrAwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjT1nHTLPWRYnjf3nHmkrjRz" target="_blank" class="baidu-highlight"ID/a: ' . $current_user-a href=";tn=44039180_cprfenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d-uhfdnHNBryu-uy7hrAwb0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErjT1nHTLPWRYnjf3nHmkrjRz" target="_blank" class="baidu-highlight"ID/a . 'br /';