WordPressで特定のカテゴリーを出力したり、非表示にしたりする場合ってありますよね。今更な感じもしますが、備忘録兼ねて掲載させて頂きます。
[html]
<div class="post-title">
<ul>
<?php query_posts($args = array(‘post_type’ => post,’posts_per_page’ => 5, ‘cat’ => 〇〇)); ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
<?php else : ?>
<p>現在表示する記事はありません</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
[/html]
「’cat’ => 〇〇」の箇所にカテゴリーのIDを入力してお使いください。
[html]
<div class="post-title">
<ul>
<?php query_posts($args = array(‘post_type’ => post,’posts_per_page’ => 5, ‘cat’ => -〇〇)); ?>
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
<?php else : ?>
<p>現在表示する記事はありません</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
[/html]
「’cat’ => -〇〇」の箇所にカテゴリーのIDを入力してお使いください。
出力と非表示の違いは、「-」があるかどうかです。そんなに難しくないですよね。上記のタグは、コピペでご自由にお使いください。コピペでタグ使用時は、自己責任でお願い致します。