WordPressテンプレートタグquery postsの使用例
query_postsを使うと条件に該当する記事を取得して、表示したい件数を指定できます。
トップページindex.phpなどに特定のカテゴリーやタグの記事を表示したい場合に便利です。
<ul> <?php query_posts($query_string ."tag=wordpress&showposts=5"); ?> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>カテゴリー(カテゴリーID)”25”の記事タイトルを5件リンク付でリスト表示
<ul> <?php query_posts($query_string ."cat=25&showposts=5"); ?> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
関連記事
- WordPressプラグイン「Timthumb Vulnerability Scanner」でTimThumbの脆弱性への対応
- WordPress プラグイン AddQuicktagがWP3.3で表示されない場合
- WordPress プラグイン Where did they go from hereでページを除外する
- カスタム投稿タイプをウィジェットの最近の投稿に含める・・WordPress
- カスタム投稿タイプで作成した記事をRSS Feedに表示させる
タグ: WordPress


