[WordPress]Underscoresテーマで、カテゴリページをタイトルだけにする方法

カテゴリ: 未分類 | タグ: ,

WordPressのUnderscoresテーマ(_s)を使用して、カテゴリページ(カテゴリの記事一覧)を表示させると、デフォルトでは記事タイトルだけでなく記事本体も出力されます。

今回、カテゴリページでは記事タイトルのみを出力させたかったため、修正を行ってみました。

作業手順

まず、wp-content\themes\THEME_NAMEのディレクトリにあるarchive.phpをコピーして、category.phpを作ります。

次に、category.phpの中をエディタで開き、下記の記述がある部分を探します。このwhileループで1ページ分の記事一覧を出力しています。

/* 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() );

endwhile;

実際の出力処理は、template-parts/content.phpで行っているため、ここの記述を変えます。先ほど確認したcategory.phpにある下記の行を変更します。

    get_template_part( 'template-parts/content', get_post_format() );

    ↓

    get_template_part( 'template-parts/content-category', get_post_format() );

template-parts/content.phpをコピーしてtemplate-parts/content-cateogry.phpを作ります。

コピーしたtemplate-parts/content-cateogry.phpを編集して、出力したいレイアウトで記事が表示されるように修正すれば完了です。


Amazonでおトクに買い物する方法
AmazonチャージでポイントGET


Amazonは買いもの前にAmazonギフト券をチャージしてポイントをゲットしないと損!

こちらもおススメ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です