ブログ

「query posts」やめて「WP Query」使わないと…

2015.10.16

ずいぶん前から使っているんだけど、備忘録で..。
ページIDが「1」の固定ページの内容を表示させるためのタグ。

<?php
$args = array(
  'cat' => 2,
);?>
<?php $the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
  while ( $the_query->have_posts() ) : $the_query->the_post();?>
<?php the_time();?><br>
<?php the_title();?>
<?php endwhile; endif;?>
<?php wp_reset_query();?>

修正しました(2016.08.23)
よく使いそうなパラメーター
cat (int) – カテゴリIDを使用します。
p (int) – 投稿のIDを使用する。
page_id (int) – 固定ページのIDを使用する。
posts_per_page (整数) – 1 ページに含める投稿数。
orderby (string) – 並び順の指定
‘ID’ – 投稿IDで並び替える。大文字に注意。
‘author’ – 著者で並び替える。
‘title’ – タイトルで並び替える。
‘date’ – 日付で並び替える。
‘modified’ – 更新日で並び替える。
‘parent’ – 投稿/固定ページの親ID順。

BLOG

Archive

Category

Recent Entry


042-783-3557
平日9:00〜19:00

フォームからの
お問い合わせ

LINEでの
お問い合わせ
電話
LINE友達登録
ページTOPヘ
Copyright © 2003-2024
seeboo design All rights reserved.