こんにちは
display post とは、Display Posts プラグインのことでしょうか?
Display Posts プラグインのカテゴリー表示は display_posts_shortcode_category_display フィルターフックで変更できそうです。
下記ページが参考になると思います。
https://displayposts.com/2019/01/08/include-the-post-categories-in-the-listing/
ishitaka 様
ご無沙汰しております、いつもありがとうございます。
はい、お察しの通り、「Display Posts」になります。
リンク先のページ拝見したのですが、ショートコードに何か記載すると、区切りのカンマを別の物へ出来るという事になりますでしょうか?
具体的にお教えいただけますと、助かります。
こんな感じではどうでしょうか。
add_filter( 'display_posts_shortcode_category_display', function( $category_display_text, $terms, $category_display, $original_atts ) {
$category_label = 'Posted in: ';
if ( isset( $original_atts['category_label'] ) ) {
$category_label = sanitize_text_field( $original_atts['category_label'] );
}
$term_output = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$term_output[] = '<a href="' . get_term_link( $term, $category_display ) . '">' . $term->name . '</a>';
}
$category_display_text = ' <span class="category-display"><span class="category-display-label">' . $category_label . '</span> ' . implode( ' ', $term_output ) . '</span>';
}
return $category_display_text;
}, 10, 4 );
ishitaka 様
コード、ありがとうございます!
うまくいきました。
ちなみに、どの辺りがカンマ消すコードになっているのでしょうか?
カンマを消しているというか、カテゴリーを丸ごと表示しています。プラグインのコード(下記)をほぼそのまま使用しています。
https://github.com/billerickson/display-posts-shortcode/blob/master/display-posts-shortcode.php#L579-L584
implode( ', ', $term_output )
↓
implode( ' ', $term_output )
ishitaka 様
そうなのですね。
該当箇所は当方も見ておりました。
ありがとうございました。