質問するログイン新規登録

回答編集履歴

2

管理画面でエラーが出たのでコメント出力中かどうかの条件分岐を追加しました。

2018/09/26 02:22

投稿

tabuu
tabuu

スコア2493

answer CHANGED
@@ -4,15 +4,17 @@
4
4
  ```
5
5
  add_filter('get_avatar_url', 'get_avatar_sex_url', 99, 3);
6
6
  function get_avatar_sex_url($url, $id_or_email, $args) {
7
+ if (have_comments()) {
7
- $sexies = get_comment_meta(get_comment_ID(), 'sex', false);
8
+ $sexies = get_comment_meta(get_comment_ID(), 'sex', false);
8
- if ($sexies) {
9
+ if ($sexies) {
9
- foreach ($sexies as $sex) {
10
+ foreach ($sexies as $sex) {
10
- if ($sex == '男性') {
11
+ if ($sex == '男性') {
11
- return 'https://s.yimg.jp/c/icon/s/bsc/2.0/mail80.png';
12
+ return 'https://s.yimg.jp/c/icon/s/bsc/2.0/mail80.png';
13
+ }
14
+ if ($sex == '女性') {
15
+ return 'https://s.yimg.jp/c/icon/s/bsc/2.0/shopping80.png';
16
+ }
12
17
  }
13
- if ($sex == '女性') {
14
- return 'https://s.yimg.jp/c/icon/s/bsc/2.0/shopping80.png';
15
- }
16
18
  }
17
19
  }
18
20
  return $url;

1

function.phpはfunctions.phpの誤りでした。

2018/09/26 02:22

投稿

tabuu
tabuu

スコア2493

answer CHANGED
@@ -1,4 +1,4 @@
1
- function.phpに以下のコードを追記してみてください。
1
+ functions.phpに以下のコードを追記してみてください。
2
2
  画像のURLはテスト用にYahooさんの画像を拝借していますのでご自身のものに置き換えてください。
3
3
 
4
4
  ```