質問失礼します。
functions.phpに下記を記述してカスタム投稿を増やしています。
/* カスタム投稿タイプを追加 */ add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'sample', //カスタム投稿タイプ名を指定 array( 'labels' => array( 'name' => __( 'サンプル' ), 'singular_name' => __( 'サンプル' ) ), 'public' => true, 'has_archive' => true, /* アーカイブページを持つ */ 'menu_position' =>5, //管理画面のメニュー順位 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields' ,'comments' ), ) ); /* カテゴリタクソノミー(カテゴリー分け)を使えるように設定する */ register_taxonomy( 'sample_cat', /* // 追加するタクソノミー名(英小文字とアンダースコアのみ) */ 'sample', /* どのカスタム投稿タイプに追加するか */ array( 'hierarchical' => true, /* trueだと親子関係が使用可能。falseで使用不可 */ 'update_count_callback' => '_update_post_term_count', 'label' => 'カテゴリー', /*管理画面上に表示される名前(投稿で言うカテゴリー)*/ 'singular_label' => 'カテゴリー', 'public' => true, 'show_ui' => true ) ); /* カスタムタクソノミー、タグを使えるようにする */ register_taxonomy( 'sample_tag', /* タクソノミーの名前 */ 'sample', /* 使用するカスタム投稿タイプ名 */ array( 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => 'タグ', 'singular_label' => 'タグ', 'public' => true, 'show_ui' => true ) ); }
作ったサンプルのカスタム投稿にカテゴリー(samplecat)を持たせました。
そしてsingle-samplecat.phpを作り下記を記述しています。
<?php get_header(); ?> <div id="main-content"> <div id="blog-content"> <section> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" class="content"> <div id="blog-title"> <h2 class="blog-first"><span><?php the_title(); ?></span></h2> </div> <div id="blog-text"> <?php the_content(); ?> </div> </article> <?php endwhile;?> <?php endif; ?> </section> <div class="paging-column"> <?php if (get_previous_post()):?> <div class="prev-column"><?php previous_post_link('%link','前の記事',true,'','samplecat'); ?></div> <?php endif; ?> <?php if (get_next_post()):?> <div class="next-column"><?php next_post_link('%link','次の記事',true,'','samplecat'); ?></div> <?php endif; ?> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
仕上がりイメージは記事の本文の下に前の記事、次の記事のリンクボタンを表示させたいのですが何も表示されません。
また制作して記事を見るとリンクが下記のようになっています。
http://shitsumon.com/sample/記事のタイトル
ページャーを正常に表示させる方法をご存知の方がいらっしゃいましたらご教授お願いいたします。
編集
https://ja.wordpress.org/support/topic/%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E6%8A%95%E7%A8%BF%E3%81%AE%E3%83%9A%E3%83%BC%E3%82%B8%E3%83%A3%E3%83%BC%E3%81%AE%E8%A1%A8%E7%A4%BA/
丸投げではなく自分なりに調べてprevious_post_linkのパラメータにタクソノミーの名前を入れる(タクソノミーとは何か)等調べてわからなかったので質問させていただきました。別サイトでも質問したのはその方が自分の知りたい事が知れる確率が上がると思ったためです。別サイトの方で問題は解決しまいした。閲覧いただいた方々ありがとうございました!
teratailでは、マルチポストは推奨されていません。https://teratail.com/help#posted-otherservice
kei344様ご丁寧に教えていただきありがとうございます。以後は自重します。
回答1件
あなたの回答
tips
プレビュー