前提・実現したいこと
wp_list_categories();で親・子・孫のカテゴリリストを出力し、それぞれに独自のスタイルを与えるためにclassを付与したいのですが、エラーが生じます。phpに詳しい方教えていただけないでしょうか。
下記のサイトの方法で試してみました。よろしくお願いします。
https://tenman.info/labo/snip/archives/1435
発生している問題・エラーメッセージ
: Declaration of MyWalker::start_el(&$output, $category, $depth, $args) should be compatible with Walker_Category::start_el(&$output, $category, $depth = 0, $args = Array, $id = 0) in $args = Array, $id = 0) in /xxx/xxx/xxx/xxx/xxx/xxx/themes/xxx/functions.php on line 0
該当のソースコード
//themes functions.php class MyWalker extends Walker_Category { function start_el(&$output, $category, $depth, $args) { extract($args); $cat_name = esc_attr( $category->name ); $link = '<a href="%1$s" rel="%2$s">%3$s</a>'; $link = sprintf($link , esc_attr( get_term_link($category) ) , $category->slug , $cat_name ); $check_mago = count( get_ancestors( $category->term_id, 'category' ) ); if($check_mago == 2 and $category->category_parent > 0 ){ $class = 'mago'; } if($check_mago == 1 and $category->category_parent > 0 ){ $class = 'kodomo'; } if($category->category_parent == 0){ $class = 'oya'; } $output .= '<li class="'.$class.'">'.$link; } } //template <?php $MyWalker = new MyWalker(); $args = array('walker' => $MyWalker); ?> <ul> <?php wp_list_categories($args); ?> </ul>
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
WordPress 5.0.4です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/17 05:48
2019/04/17 07:00
2019/04/18 17:07