新着情報に投稿ページと固定ページを表示したい
-
トップページに新着情報に特定の固定ページと特定のカテゴリーを日付順で表示したいのですが特定のカテゴリーが表示されません。複数の特定のカテゴリーを表示したいと思うのですが、一つなら表示されます。
function whatsnews(){
//固定ページのスラッグを配列で指定(ダブルコーテーションとカンマ区切り)
$koteipageslugs = array(“page01”,
“page02”);
//指定されたスラッグの固定ページ配列を得る
foreach ($koteipageslugs as $value) {
$args = array(
‘post_type’ => ‘page’,
‘name’ => $value,
);
$query = new WP_Query( $args );
$query->the_post();
if ( have_posts() ) {
$whatsnewary[] = array(‘title’=>get_the_title(),’url’=>get_the_permalink(),’modifieddate’=>get_the_date(‘Y年n月j日’),’date’=>get_the_date(‘Y-m-d’));
}//end if
}//end foreachwp_reset_postdata();//ループをリセット
//新着投稿5件を得る
$args = array(
‘category_name’ => ‘cat01’, ‘cat02’,//特定のカテゴリースラッグで複数指定したいのです
‘posts_per_page’ => 5,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$whatsnewary[] = array(‘title’=>get_the_title(),’url’=>get_the_permalink(),’modifieddate’=>get_the_date(‘Y年n月j日’),’date’=>get_the_date(‘Y-m-d’));
}//end while
}//end if//配列を日付順に並べ替える
foreach ($whatsnewary as $key => $value){
$key_id[$key] = $value[‘date’];
}
array_multisort ( $key_id , SORT_DESC , $whatsnewary);//最新5件表示
$count = 0;
foreach( $whatsnewary as $value ){
echo ‘- ‘.$value[‘modifieddate’].’<span>’.$value[‘title’].'</span>
‘;
$count++;
if($count==5){
break;
}
}//print_r($whatsnewary);
wp_reset_postdata();//ループをリセット
}
- トピック「新着情報に投稿ページと固定ページを表示したい」には新たに返信することはできません。