目次
概要
投稿ヘッダーの
・投稿日
・更新日
・投稿者
・カテゴリー
・コメント数
の表示をカスタマイズする。
手順
・ [ダッシュボード]→[外観]→[テーマの編集]を選択
・ テーマファイルから[includes]→[mh-custom-functions.php]を選択
・以下の部分を編集する
更新日を表示する
get_the_date() を使用して投稿日を表示している箇所の横に
get_the_modified_date() で更新日を表示するコードを追加する。
参考
PROVAI.ciao – MH Magazine Lite:更新日を表示させる
投稿者を非表示にする
get_the_author_meta()を呼び出している行をコメントアウトする。
カテゴリーをパンくずリスト表示する
全てのカテゴリー階層を表示する場合
get_the_category() で取得したカテゴリー配列を全要素に対して
get_category_parents() で親カテゴリーも含めて階層表示する。
$_categories = get_the_category();
foreach ($_categories as $_category) {
echo '<br/><span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i>' . get_category_parents($_category->term_id, true) . '</span>' . "\n";
}
カテゴリー階層を1件だけ表示する場合
カテゴリーを重複登録しない場合、親階層を作成後に子階層を作成するため、カテゴリー配列の最後の要素を取得すれば、最下層のカテゴリーを表示できる。
$_categories = get_the_category(); echo '<br/><span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i><a href="' . home_url() . '">TOP</a>/' . get_category_parents($_categories[count($_categories) - 1]->term_id, true) . '</span>' . "\n";
ソースコード
/***** Post Meta *****/
if (!function_exists('mh_magazine_lite_post_meta')) {
function mh_magazine_lite_post_meta() {
echo '<p class="mh-meta entry-meta">' . "\n";
echo '<span class="entry-meta-date updated"><i class="fa fa-clock-o"></i><a href="' . esc_url(get_month_link(get_the_time('Y'), get_the_time('m'))) . '">' . get_the_date() . '</a></span>' . "\n";
echo '<span class="entry-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' . "\n";
echo '<span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i>' . get_the_category_list(', ', '') . '</span>' . "\n";
echo '<span class="entry-meta-comments"><i class="fa fa-comment-o"></i><a class="mh-comment-scroll" href="' . esc_url(get_permalink() . '#mh-comments') . '">' . absint(get_comments_number()) . '</a></span>' . "\n";
echo '</p>' . "\n";
}
}
add_action('mh_post_header', 'mh_magazine_lite_post_meta');
/***** Post Meta (Loop) *****/
if (!function_exists('mh_magazine_lite_loop_meta')) {
function mh_magazine_lite_loop_meta() {
echo '<span class="mh-meta-date updated"><i class="fa fa-clock-o"></i>' . get_the_date() . '</span>' . "\n";
if (in_the_loop()) {
echo '<span class="mh-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' . "\n";
}
echo '<span class="mh-meta-comments"><i class="fa fa-comment-o"></i>';
mh_magazine_lite_comment_count();
echo '</span>' . "\n";
}
}
/***** Post Meta *****/
if (!function_exists('mh_magazine_lite_post_meta')) {
function mh_magazine_lite_post_meta() {
echo '<p class="mh-meta entry-meta">' . "\n";
echo '<span class="entry-meta-date updated"><i class="fa fa-clock-o"></i><a href="' . esc_url(get_month_link(get_the_time('Y'), get_the_time('m'))) . '">' . get_the_date() . '</a></span>' . "\n";
if (get_the_date('Ymd') < get_the_modified_date('Ymd')) {
echo '<span class="entry-meta-date updated">(更新:<a href="' . esc_url(get_month_link(get_the_modified_date('Y'), get_the_modified_date('m'))) . '">' . get_the_modified_date() . '</a>)</span>' . "\n";
}
//echo '<span class="entry-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' . "\n";
echo '<span class="entry-meta-comments"><i class="fa fa-comment-o"></i><a class="mh-comment-scroll" href="' . esc_url(get_permalink() . '#mh-comments') . '">' . absint(get_comments_number()) . '</a></span>' . "\n";
$_categories = get_the_category();
echo '<br/><span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i><a href="' . home_url() . '">TOP</a>/' . get_category_parents($_categories[count($_categories) - 1]->term_id, true) . '</span>' . "\n";
// foreach ($_categories as $_category) {
// echo '<br/><span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i>' . get_category_parents($_category->term_id, true) . '</span>' . "\n";
// }
echo '</p>' . "\n";
}
}
add_action('mh_post_header', 'mh_magazine_lite_post_meta');
/***** Post Meta (Loop) *****/
if (!function_exists('mh_magazine_lite_loop_meta')) {
function mh_magazine_lite_loop_meta() {
$update_date = '';
if (get_the_date('Ymd') < get_the_modified_date('Ymd')) {
$update_date = '(更新:' . get_the_modified_date() . ')';
}
echo '<span class="mh-meta-date updated"><i class="fa fa-clock-o"></i>' . get_the_date() . $update_date . '</span>' . "\n";
// if (in_the_loop()) {
// echo '<span class="mh-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' . "\n";
// }
echo '<span class="mh-meta-comments"><i class="fa fa-comment-o"></i>';
mh_magazine_lite_comment_count();
echo '</span>' . "\n";
}
}