WordPressのindex一覧を特定のカテゴリーにするのでR

WordPressでは、サイトの最初のindex一覧では、投稿の新しい日付順に並んでいるのでR。

このindex一覧を、特定のカテゴリーだけにしたいのでR。

テーマによっては、index一覧を特定カテゴリーできる場合もR。その場合は、たいがい「外観」→「カスタマイズ」でその項目があるのでR。

しかし、

一般的なテーマはそれがないのでR。そのために、サイトの最初のindex一覧を特定のカテゴリーに固定するには、ソースをいじる必要があるのでR。

まずは、「外観」→「テーマ編集」でindex.phpを覗くのでR。

例えば、このTwenty Sixteenでは、

<?php
			// Start the loop.
			while ( have_posts() ) : the_post();

				/*
				 * Include the Post-Format-specific template for the content.
				 * If you want to override this in a child theme, then include a file
				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
				 */
				get_template_part( 'template-parts/content', get_post_format() );

			// End the loop.
			endwhile;

があるのでR。このwhile ( have_posts() ) : the_post();のループが始まる前の

<?php

の前に、

<?php query_posts("cat=1");>

を挿入するのでR。ここではカテゴリー”1″の一覧がindex一覧となるのでR。ちなみに、カテゴリーのIDの番号は、

「投稿」→「カテゴリー」を覗いて、カテゴリーの名前の上にマウスカーソルを置くと、左下に

と出るので、そこに書いてある番号がカテゴリーのIDとなるのでR。この図の場合は”3″なのでR。

詳しくは、ここを参考にするのでR。





(広告)月額900円(税抜)から、高速・多機能・高安定レンタルサーバー『エックスサーバー』
(広告)WordPressの運用に特化したレンタルサーバー『wpXレンタルサーバー』
(広告)年間920円(税抜)からの格安ドメイン取得サービス─ムームードメイン─




この記事をシェアできます。