2016/11/08
固定ページ Wordpress
備忘録です。
参考サイト
[WordPress] どうしても固定ページテンプレートでページ送り付きのアーカイブが作りたいのよと言う場合
【参考サイトのタグ】page-***.phpに追加記述
<?php
/**
* Template Name: Archive Page */
?>
<?php
$paged = (int) get_query_var('paged');
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
else:
get_template_part( 'content', 'none' );
endif;
if ($the_query->max_num_pages > 1) {
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => max(1, $paged),
'total' => $the_query->max_num_pages
));
}
wp_reset_postdata();
?>
カスタム投稿だったので、上記をこのようにしました。
【例】カスタム投稿testのsportsタームを表示
<?php
/**
* Template Name: Archive Page */
?>
/*ここにヘッダー、パンくずなどを追加*/
<?php
$paged = (int) get_query_var('paged');
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'test', //カスタム投稿のtest
'tax_query' => array(
array(
'taxonomy' => 'test_cate',//カスタム投稿のタクソノミー
'field' => 'slug',
'terms' => 'sports',//カスタム投稿のターム
),
),
'post_status' => 'publish'
);
$the_query = new WP_Query($args);
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
/*ここに表示したい内容を記述*/
<p><?php the_title(); ?></p>
<p><?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<div class"testpage">
<?php if ($the_query->max_num_pages > 1) {
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => max(1, $paged),
'total' => $the_query->max_num_pages
));
}
wp_reset_postdata();
?>
</div>
/*ここにフッターなどを追記*/
ゼヒトモ内でのプロフィール: ROCKSTREAM, ゼヒトモのホームページ作成・制作サービス, 仕事をお願いしたい依頼者と様々な「プロ」をつなぐサービス
2025/01/31
JQuery
2025/01/01
神社
御朱印
相模原
2024/10/27
ブラウザ
カスタム投稿
Wordpress
2024/08/20
神社
御朱印
2024/07/06
神社
御朱印