###前提・実現したいこと
- リストWordPressのコメント欄をカスタマイズしたい
- リストWEB上の文献を参考にカスタマイズしてみた→「【wordpress】コメントの入力欄を追加する/wp_list_comments表示カスタマイズ」
###発生している問題・エラーメッセージ
- 投稿ページのコメント欄はうまく表示される
- TOPページのサイドバーにある投稿欄ウィジェットでエラーが出る
Notice: Trying to get property of non-object in /var/www/wordpress/wp-includes/comment-template.php on line 665
###該当のソースコード
apply_filtersのある行がline 665
php
1function get_comment_ID() { 2 $comment = get_comment(); 3 4 /** 5 * Filters the returned comment ID. 6 * 7 * @since 1.5.0 8 * @since 4.1.0 The `$comment_ID` parameter was added. 9 * 10 * @param int $comment_ID The current comment ID. 11 * @param WP_Comment $comment The comment object. 12 */ 13 return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment ); 14}
function.phpに下記のコードを記述し呼び出しています。
php
1////////出力 2////性別 3 4add_filter( 'get_comment_author_link', 'attach_sex_to_author' ); 5 6 7function attach_sex_to_author( $author ) { 8 $sexies = get_comment_meta( get_comment_ID(), 'sex'); 9 if ( $sexies ) { 10 foreach ($sexies as $sex) 11 $author .= $sex . ' '; 12 } 13 return $author; //コメント者の後に続けて出力。 14} 15////年齢層 16add_filter( 'get_comment_author_link', 'attach_age_to_author' ); 17 18 19function attach_age_to_author( $author ) { 20 $ages = get_comment_meta( get_comment_ID(), 'commenterAge'); 21 if ( $ages ) { 22 foreach ($ages as $age) 23 $author .= '(' .$age . ')'; 24 } 25 return $author; //コメント者の後に続けて出力。 26} 27
###試したこと
フィルターフックget_comment_author_link
が投稿欄では作動するけど、TOPページでは作動しないのが原因?と推測し、他のフィルターフックをget_comment_ID
などをフックに設定したり試しましたが、うまくいきませんでした。
対処方法を教えていただければありがたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/01 04:36