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

wordpress判斷用戶等級(jí)來(lái)顯示不同的評(píng)論頭像

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

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

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

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

為了解決這個(gè)問(wèn)題,有以下二個(gè)方法:

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

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

  1. wordpress網(wǎng)站把用戶分為5個(gè)等級(jí),分別為:管理員、編輯、作者、投稿者、訂閱者,當(dāng)然不要忘記給沒(méi)有注冊(cè)的游客也做一張頭像圖片。我們首先需要對(duì)這6個(gè)用戶的用戶各自創(chuàng)建一個(gè)頭像圖片,圖片的大小為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中;
    //評(píng)論 判斷管理員
    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;
    }
    //評(píng)論 判斷編輯
    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;
    }
    //評(píng)論 判斷作者
    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;
    }
    //評(píng)論 判斷投稿者
    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;
    }
    //評(píng)論 判斷訂閱者
    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ù)是用來(lái)判斷網(wǎng)站文章的評(píng)論者是哪一個(gè)等級(jí)。
  5. 將以下的代碼放到自己網(wǎng)站的評(píng)論模板comments.php中,查找一下評(píng)論模板中顯示頭像的代碼。(含有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ā)布評(píng)論時(shí),網(wǎng)站程序就會(huì)自動(dòng)判斷用戶的級(jí)別,并且顯示設(shè)定的相應(yīng)的頭像了。
    wordpress判斷用戶等級(jí)來(lái)顯示不同的評(píng)論頭像

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

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

上一篇:wordpress下拉菜單,二級(jí)菜單制作

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