賢威のテンプレートで関連記事を自動で表示させるための忘備録です。
・関連記事を自動で表示
・関連記事の数を変更
・関連記事の表示を2列
カテゴリのみ変更タグは不使用
functions.phpを直接書き込めない場合、ダウンロードして編集しUTF-8/LFで保存
関連記事を自動で表示
テーマのための関数 (functions.php)
1098行あたりにある「// カテゴリから取得する」
// カテゴリから取得する
$category_relation = get_post_meta(get_the_ID(), ‘category_relation’, true);
if (isset($category_relation) && $category_relation == “y”) {
$category_relation = get_post_meta(get_the_ID(), ‘category_relation’, true);
if (isset($category_relation)) {
&& $category_relation == “y”を削除する。
関連記事の数を変更
// カテゴリから取得する
if (count($relation) < 5)
の数字を表示したい件数に変更x3か所
$args = array( ‘posts_per_page’ => 5
の数字を表示したい件数に変更x2か所
関連記事の表示を2列
PC → 2列
スマホ → 1列
CSSに追加
/*————————————-
関連記事を2列表示
————————————-*/
.related-articles-thumbs01 li {
width: 48%;
display: inline-block;
vertical-align: top;
font-size: 0.9em;
}
/*————————————-
width950px以下で関連記事を2列表示を解除
————————————-*/
@media only screen and (max-width : 950px){
.related-articles-thumbs01 li {
width: auto;
}
}