PHP
1<?php echo preg_replace( '/</a>\s((\d+))/', ' $1</a>', wp_list_authors( 'optioncount=1&echo=0' ) ); ?>
サイドバーにカテゴリーと同じ感じで、投稿者リストを表示しているのですが、
書き出される<li>にcssのクラス名を付与する方法を教えてください。
よろしくお願いします。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答1件
0
ベストアンサー
フィルターフックとか無いようなのでズバッとコピーして
function my_wp_list_authors( $args = '' ) { global $wpdb; $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '' ); $args = wp_parse_args( $args, $defaults ); $return = ''; $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); $query_args['fields'] = 'ids'; $authors = get_users( $query_args ); $author_count = array(); foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) { $author_count[$row->post_author] = $row->count; } foreach ( $authors as $author_id ) { $author = get_userdata( $author_id ); if ( $args['exclude_admin'] && 'admin' == $author->display_name ) { continue; } $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0; if ( ! $posts && $args['hide_empty'] ) { continue; } if ( $args['show_fullname'] && $author->first_name && $author->last_name ) { $name = "$author->first_name $author->last_name"; } else { $name = $author->display_name; } if ( ! $args['html'] ) { $return .= $name . ', '; continue; // No need to go further to process HTML. } if ( 'list' == $args['style'] ) { global $post; if( $author->ID == $post->post_author ) { $return .= '<li class="current">'; } else { $return .= '<li>'; } } $link = sprintf( '<a href="%1$s" title="%2$s">%3$s', get_author_posts_url( $author->ID, $author->user_nicename ), /* translators: %s: author's display name */ esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ), $name ); if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { $link .= ' '; if ( empty( $args['feed_image'] ) ) { $link .= '('; } $link .= '<a href="' . get_author_feed_link( $author->ID, $args['feed_type'] ) . '"'; $alt = ''; if ( ! empty( $args['feed'] ) ) { $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; $name = $args['feed']; } $link .= '>'; if ( ! empty( $args['feed_image'] ) ) { $link .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />'; } else { $link .= $name; } $link .= '</a>'; if ( empty( $args['feed_image'] ) ) { $link .= ')'; } } if ( $args['optioncount'] ) { $link .= ' ('. $posts . ')'; } $return .= $link; $return .= ( 'list' == $args['style'] ) ? '</li>' : ', '; } $return = rtrim( $return, ', ' ); if ( ! $args['echo'] ) { return $return; } echo $return; }
こうやって出すとかどうでしょう?
<?php echo my_wp_list_authors( 'optioncount=1&echo=0' ); ?>
コードを書き変えました。
ページ作成者が一致したら<li class="current">
にする
で、合ってるんでしょうか…
とりあえずpreg_replaceとかでは無理でしょうね。
出力前に置換するなんて不可能ですよ。
投稿2018/03/09 04:36
編集2018/03/09 06:02退会済みユーザー
総合スコア0
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/09 05:15
2018/03/12 11:41
退会済みユーザー
2018/03/12 15:36