2026.06.25(木) / 04:37
どこで最新の記事の件数を指定しているか?
- ID
- 38420
- Published
- 2026-06-25 04:37
- Modified
- 2026-06-25 04:37
- Author
- khiro
- Categories
- デフォルト
当サイトの最新の記事の数が多すぎると感じた

3件に修正したい
件数を制御している箇所
post-index.phpの11行目〜15行目に答えがあった
<h2 class="front-sec__ttl --sp-center">最新の記事</h2>
<p class="life-article__lead">技術と思想と日々の発見を、自分の言葉で整理する。</p>
<?php endif; ?>
<?php get_template_part('template-parts/last-modified-posts'); ?>
template-parts/last-modified-postsを見に行こう
13行目〜23行目でWP_Queryの設定を行っていた
$post_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => 20,
'orderby' => 'modified',
'order' => 'DESC',
'post__not_in' => kihiro_excluded_post_ids(),
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
posts_per_pageの20を3に修正してみる
$post_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => 3,
'orderby' => 'modified',
'order' => 'DESC',
'post__not_in' => kihiro_excluded_post_ids(),
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
フロント画面の記事の件数は、変化しない。

ということは、原因は別にある
VSCodeの全ソース検索を活用する
command + Shift + F で、現在開いているフォルダの全ソース検索をかけることができる
2022年にWEB制作フリーランスをしていた時に、派遣先企業で週3日働いていて、その時の先輩エンジニアに教えてもらった

発見
contant.phpの295行目に答えがあった
$query->set('posts_per_page', 20);
これを以下に修正する
$query->set('posts_per_page', 3);
件数の削減に成功した

これでスマホのスクロールの負担を減らすことができた

調整
サイドバーの年月が間延びしているので、アコーディオンを閉じておこう

こちらについては、プログラミングの関心の分離の概念よろしく、次の記事で書くことにする