中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

wordpress判斷用戶等級來顯示不同的評論頭像

2018-11-02    來源:學(xué)做網(wǎng)站論壇

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

wordpress程序的評論頭像是自動的調(diào)用全球gravatar頭像,wordpress程序本身是不支持用戶設(shè)置頭像的,網(wǎng)站后臺只支持“對于那些沒有自定義頭像的用戶,您可以顯示一個通用頭像或者根據(jù)他們的郵件地址產(chǎn)生一個頭像!本W(wǎng)站管理員可以設(shè)置一些“小怪物頭像”。
wordpress判斷用戶等級來顯示不同的評論頭像

如果你自己要設(shè)置自己頭像,必須使用你的郵箱到gravatar網(wǎng)站上去設(shè)置。隨著gravatar網(wǎng)站被國內(nèi)屏蔽,即使你設(shè)置了個性頭像,也沒法在自己網(wǎng)站上顯示出來。

為了解決這個問題,有以下二個方法:

方法一:安裝WordPress 自定義頭像插件:WP User Avatar

方法二:根據(jù)wordpress程序開發(fā)手冊寫出的通過判斷用戶的等級去顯示他的頭像。步驟如下:

  1. wordpress網(wǎng)站把用戶分為5個等級,分別為:管理員、編輯、作者、投稿者、訂閱者,當(dāng)然不要忘記給沒有注冊的游客也做一張頭像圖片。我們首先需要對這6個用戶的用戶各自創(chuàng)建一個頭像圖片,圖片的大小為48px*48px。
  2. 將這5張圖片分別取名為1.jpg,2.jpg,3.jpg,4.jpg,5.jpg ,6.jpg,并把它們放到網(wǎng)站主題文件夾下的images文件夾。
  3. 將以下函數(shù)放到自己網(wǎng)站的模板函數(shù)functions.php中;
    //評論 判斷管理員
    function is_admin_comment( $comment_ID = 0 ) {
    $comment = get_comment( $comment_ID );
    $admin_comment = false;
    if($comment->user_id == 1){
    $admin_comment = true;
    }
    return $admin_comment;
    }
    //評論 判斷編輯
    function is_editor_comment( $comment_ID = 0 ) {
    $comment = get_comment( $comment_ID );
    $editor_comment = false;
    if($comment->user_id == 1){
    $editor_comment = true;
    }
    return $editor_comment;
    }
    //評論 判斷作者
    function is_author_comment( $comment_ID = 0 ) {
    $comment = get_comment( $comment_ID );
    $author_comment = false;
    if($comment->user_id == 1){
    $author_comment = true;
    }
    return $author_comment;
    }
    //評論 判斷投稿者
    function is_Contributor_comment( $comment_ID = 0 ) {
    $comment = get_comment( $comment_ID );
    $Contributor_comment = false;
    if($comment->user_id == 1){
    $Contributor_comment = true;
    }
    return $Contributor_comment;
    }
    //評論 判斷訂閱者
    function is_subscriber_comment( $comment_ID = 0 ) {
    $comment = get_comment( $comment_ID );
    $subscriber_comment = false;
    if($comment->user_id == 1){
    $subscriber_comment = true;
    }
    return $subscriber_comment;
    }
  4. 以上函數(shù)是用來判斷網(wǎng)站文章的評論者是哪一個等級。
  5. 將以下的代碼放到自己網(wǎng)站的評論模板comments.php中,查找一下評論模板中顯示頭像的代碼。(含有g(shù)ravatar的字樣)
    <?php
    if (is_admin_comment($comment->comment_ID)){?>
    <img src="<?php bloginfo('template_directory'); ?>/images/1.jpg" width="48px" alt="管理員頭像"/>
    <?php } elseif (is_editor_comment($comment->comment_ID)){?>
    <img src="<?php bloginfo('template_directory'); ?>/images/2.jpg" width="48px" alt="編輯頭像"/>
    <?php } elseif (is_author_comment($comment->comment_ID)){?>
    <img src="<?php bloginfo('template_directory'); ?>/images/3.jpg" width="48px" alt="作者頭像"/>
    <?php } elseif (is_Contributor_comment($comment->comment_ID)){?>
    <img src="<?php bloginfo('template_directory'); ?>/images/4.jpg" width="48px" alt="投稿者頭像"/>
    <?php } elseif (is_subscriber_comment($comment->comment_ID)){?>
    <img src="<?php bloginfo('template_directory'); ?>/images/5.jpg" width="48px" alt="訂閱者頭像"/>
    <?php } else {?>
    <img src="<?php bloginfo('template_directory'); ?>/images/6.jpg" width="48px" alt="游客頭像"/>
    <?php }?>
  6. 這樣當(dāng)有用戶在網(wǎng)站上發(fā)布評論時,網(wǎng)站程序就會自動判斷用戶的級別,并且顯示設(shè)定的相應(yīng)的頭像了。
    wordpress判斷用戶等級來顯示不同的評論頭像

標(biāo)簽: 代碼 網(wǎng)站的模板

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:wordpress下拉菜單,二級菜單制作

下一篇:wordpress網(wǎng)站導(dǎo)航不顯示分類目錄