Last active
December 3, 2021 06:08
-
-
Save rocket-martue/8ca484a050348133b5556594e3bfa605 to your computer and use it in GitHub Desktop.
Snow Monkey で複数のカテゴリーラベルを表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* disable .c-entry-summary__term | |
* 各投稿一覧で デフォルトの taxonomy ラベルを削除 | |
* | |
* @param string $html はコンテンツの中身. | |
*/ | |
add_filter( | |
'snow_monkey_template_part_render_template-parts/loop/entry-summary/term/term', | |
function ( $html ) { | |
$html = NULL; | |
return $html; | |
} | |
); | |
/** | |
* 投稿一覧で taxonomy のラベルをタイトルの上に表示 | |
* | |
* @param string $html はコンテンツの中身. | |
*/ | |
add_filter( | |
'snow_monkey_template_part_render_template-parts/loop/entry-summary/title/title', | |
function ( $html ) { | |
$taxonomy = 'category'; | |
$tags = ''; | |
$postid = get_the_ID(); | |
$post_terms = get_the_terms( $postid, $taxonomy ); | |
$published = get_the_time( get_option( 'date_format' ) ); | |
$timestamp = get_the_time( 'c' ); | |
if ( ! empty( $post_terms ) ) { | |
$tags = '<ul class="' .$taxonomy. '-tags taxonomy-tags">'; | |
foreach ( $post_terms as $post_term ) { | |
$term_name = $post_term->name; | |
$slug = $post_term->slug; | |
$term_id = $post_term->term_id; | |
$tags .= '<li class="' .$taxonomy. '-' .$term_id.' ' .$slug.' tags">' . $term_name . '</li>'; | |
} | |
$tags .= '<li class="published"><i class="far fa-clock" aria-hidden="true"></i><span class="screen-reader-text">投稿日</span><time datetime="'. $timestamp .'">'. $published .'</time></li>'; | |
$tags .= '</ul>'; | |
} else { | |
$tags = '<ul class="taxonomy-tags">'; | |
$tags .= '<li class="published"><i class="far fa-clock" aria-hidden="true"></i><span class="screen-reader-text">投稿日</span><time datetime="'. $timestamp .'">'. $published .'</time></li>'; | |
$tags .= '</ul>'; | |
} | |
$html = str_replace( '</h2>', '</h2>' .$tags, $html ); | |
return $html; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CSS