カスタム投稿とそのタクソノミーを使いシングルPHPを作成しています。
ページャーの前の記事へと次の記事へのリンクが付きません。どなたかお助けください。
パーマリンクの設定は/%blog_1(カテゴリー・ターム名)%/%post_id%
試したこと
・next_posts_link();を試しました。
・next_post_link();を試しました。
・Plugin Ambrosite Next/Previous Post Link Plusを試しました。
/* functions.php カスタム投稿とタクソノミーの設定 */
php
1//ブログカスタム投稿 2 add_action('init', 'my_technic_init2'); 3function my_technic_init2() 4{ 5 $labels = array( 6 'name' => _x('ブログ', 'post type general name'), 7 'singular_name' => _x('ブログ', 'post type singular name'), 8 'add_new' => _x('新規作成', 'works'), 9 'add_new_item' => __('ブログを書く'), 10 'edit_item' => __('ブログを編集'), 11 'new_item' => __('新しいブログ'), 12 'view_item' => __('ブログを見てみる'), 13 'search_items' => __('ブログを探す'), 14 'not_found' => __('ブログはありません'), 15 'not_found_in_trash' => __('ゴミ箱にブログはありません'), 16 'parent_item_colon' => '' 17 ); 18 $args = array( 19 'labels' => $labels, 20 'public' => true, 21 'publicly_queryable' => true, 22 'show_ui' => true, 23 'query_var' => true, 24 'rewrite' => true, 25 'capability_type' => 'post', 26 'hierarchical' => false, 27 'menu_position' => 5, 28 'supports' => array('title','editor','thumbnail','custom-fields','excerpt','revisions','page-attributes','comments'), 29 'has_archive' => true 30 ); 31 register_post_type('blog',$args); 32 //ここが原因かも? 33 // flush_rewrite_rules( false ); 34 35 //カテゴリータイプ 36 $args = array( 37 'label' => 'ブログカテゴリー', 38 'public' => true, 39 'show_ui' => true, 40 'query_var' => true, 41 'hierarchical' => true, 42 'rewrite' => true, 43 ); 44 register_taxonomy('blog_1','blog', $args); 45 } 46
/* single-blog.php カスタム投稿のブロクのシングル */
php
1<article id="blog_sing_article" class="site-content"> 2 3 <?php if(have_posts()) : while(have_posts()) : the_post(); ?> 4 5 <ul id="blog_date_ul"> 6 <li class="blog_single_date" itemprop="datePublished" datetime="<?php the_time('c');?>"> 7 <i class="fa fa-clock-o" aria-hidden="true"></i> 8 <?php the_time('Y/m/d');?> 9 </li> 10<?php 11//特定記事のタクソノミー取得 12$terms = get_the_terms($post->ID, 'blog_1'); 13if ($terms): 14foreach ($terms as $value): 15?> 16 <li class="blog_single_category"><?php echo $value->name; ?></li> 17<?php endforeach; endif;?> 18 </ul> 19 20 <div id="blog_post"> 21 22 <?php the_content(); ?> 23 24 </div> 25 26 27 <?php endwhile; ?> 28 29 30 <div class="nav-below"> 31 <span class="nav-previous"><?php next_posts_link('前の記事へ') ?></span> 32 <span class="nav-next"><?php previous_posts_link('次の記事へ') ?></span> 33 </div><!-- /.nav-below --> 34 35 36 <?php endif; ?> 37<?php wp_reset_query(); ?> 38</article>
回答2件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。