カスタム投稿タイプのアーカイブページのページング
-
フォーラムの中でいくつか同じような投稿を見て参考にしたのですが、なぜかうまく動作しません。宜しければご教授いただければと思います。
投稿数は認識されていると思うのですが、2ページに移動した時も1ページ目と同じ内容になってしまいます。functions.phpに以下を記述してカスタム投稿タイプを作成しています。
add_action(‘init’, ‘tblog_init’);
function tblog_init()
{
$labels = array(
‘name’ => ‘技術ブログ’,
‘singular_name’ => ‘技術ブログ’,
‘add_new’ => ‘新規作成’,
‘add_new_item’ => ‘技術ブログの登録’,
‘edit_item’ => ‘技術ブログを編集する’,
‘new_item’ => ‘新しい技術ブログ’,
‘view_item’ => ‘技術ブログ表示’,
‘search_items’ => ‘技術ブログ検索’,
‘not_found’ => ‘技術ブログが見つかりません’,
‘not_found_in_trash’ => ‘ゴミ箱に技術ブログはありません’,
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘has_archive’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
// ‘supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’)
‘supports’ => array(‘title’,’editor’,’page-attributes’,’comments’)
);
register_post_type(‘tblog’,$args);
//カテゴリータイプ
$args = array(
‘label’ => ‘技術ブログのカテゴリー’,
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => true
);
register_taxonomy(‘tblog_category’,’tblog’,$args);
flush_rewrite_rules( false );
}次に『archive-tblog.php』専用のアーカイブページを作成しました。
記述内容は以下になります。<?php
$wp_query = new WP_Query();
$param = array(
‘posts_per_page’ => ‘3’, //表示件数。-1なら全件表示
‘post_type’ => ‘tblog’, //カスタム投稿タイプの名称を入れる
‘post_status’ => ‘publish’, //取得するステータス。publishなら一般公開のもののみ
‘orderby’ => ‘ID’, //ID順に並び替え
‘order’ => ‘DESC’
);
$wp_query->query($param);
if($wp_query->have_posts()): while($wp_query->have_posts()) : $wp_query->the_post();
?><div class=”fes_post_box”>
<p class=”mb10″>” title=”<?php the_title_attribute(); ?>”><span class=”bold font22″><?php the_title(); ?></span>
<?php the_time(‘Y/m/d’); ?></p>
<p class=”mb10″><img class=”top_cimg” src=”<?php echo catch_that_image(); ?>” alt=”” width=”200″ /><?php echo my_excerpt(200); ?></p>
<p>” class=”more-link”>▼続きを読む</p>
<div class=”clear”></div>
</div>
<?php endwhile; endif; ?><!– /pagenav –>
<div class=”pagenav”><?php global $wp_rewrite;
$paginate_base = get_pagenum_link(1);
if (strpos($paginate_base, ‘?’) || ! $wp_rewrite->using_permalinks()) {
$paginate_format = ”;
$paginate_base = add_query_arg(‘paged’, ‘%#%’);
} else {
$paginate_format = (substr($paginate_base, -1 ,1) == ‘/’ ? ” : ‘/’) .
user_trailingslashit(‘page/%#%/’, ‘paged’);;
$paginate_base .= ‘%_%’;
}
echo paginate_links( array(
‘base’ => $paginate_base,
‘format’ => $paginate_format,
‘total’ => $wp_query->max_num_pages,
‘mid_size’ => 3,
‘current’ => ($paged ? $paged : 1),
)); ?></div>
<!– pagenav/ –>記述内容などで間違っていましたらご指摘お願いします。
- トピック「カスタム投稿タイプのアーカイブページのページング」には新たに返信することはできません。