Blog

【WordPress】月別アーカイブの表示変更

2016/03/21

投稿 Wordpress

備忘録です。

月別アーカイブの「2017年1月」を「2017/01」に変更します。

参考サイト
WordPress 月別アーカイブの年月表示をカスタマイズする方法

function.phpに記述

月の表記を「2017.1」にして表示

/* 【出力カスタマイズ】 wp_get_archives の年表記を置き換える */
function my_archives_link($html){
  $html = str_replace('年','.',$html);
  $html = str_replace('月','',$html);
  return $html;
}
add_filter('get_archives_link', 'my_archives_link');

月の表記を「2017.01」と二桁にして表示

/* 【出力カスタマイズ】wp_get_archives の年表記を置き換える */
add_filter('gettext', 'my_gettext', 20, 3);
function my_gettext($translated_text, $original_text, $domain) {
  if ($original_text == '%1$s %2$d') {
    $translated_text = '%2$s.%1$02d';
  }
  return $translated_text;
}

「'%2$s.%1$02d'」を「'%2$s/%1$02d'」にすると「●●/●●」になります。

アーカイブページのタイトルを「2017.01」にする
archive.phpに記述

<?php
  $tit_monthnum = get_query_var('monthnum'); // 月の値を取り出す
  echo get_query_var('year').'.'. sprintf("%02d",$tit_monthnum); // 値を二桁に変更
?>

カテゴリー

月間アーカイブ

MORE

ミュージシャンズ・プラザ

神社仏閣ホームーページ制作

ホームページ制作問合せ