最近在更新一個主題的時候也加入了該功能效果,實現的方法是透過載入 javascript 的 md5 函式轉換捕獲的郵箱輸入框的輸入的 email 地址,然後組合成對應的 gravatar 頭像連結,最後用 setAttribute 改變 img 的 src 地址。

操作步驟:
1 、下載 js 檔案,並上傳至當前企業網站模板主題資料夾
js-md5-gravatar.zip
2 、編輯當前主題的 comments.php 檔案,在要即時顯示頭像對應的檔案位置新增程式碼:
<span%20style="color: #000000; font-weight: bold;"><?php <span%20style="color: #000088;">$email <span%20style="color: #339933;">= <span%20style="color: #009900;">(<span%20style="color: #000088;">$user_ID<span%20style="color: #009900;">) ? get_the_author_meta<span%20style="color: #009900;">(<span%20style="color: #0000ff;">'user_email'<span%20style="color: #339933;">, <span%20style="color: #000088;">$user_ID<span%20style="color: #009900;">) <span%20style="color: #339933;">: <span%20style="color: #000088;">$comment_author_email<span%20style="color: #339933;">;<span%20style="color: #000000; font-weight: bold;">?><img id="real-time-gravatar" src="http://www.gravatar.com/avatar/<span%20style="color: #000000; font-weight: bold;"><?php <span%20style="color: #b1b100;">echo <span%20style="color: #990000;">md5<span%20style="color: #009900;">(<span%20style="color: #000088;">$email<span%20style="color: #009900;">)<span%20style="color: #339933;">;<span%20style="color: #000000; font-weight: bold;">?>?s=60&d=identicon&r=G" alt="gravatar 頭像" />
<span%20style="color: #ff0000;"> 注:程式碼中的 60 表示影像圖片的大小
3 、在 comments.php 檔案第一行新增以下呼叫程式碼:
<span%20style="color: #ff0000;"> 注:如果 js 檔案路徑有改動,請修改相應的路徑位置
儲存檔案,重新整理網頁後,測試成功。