サポート » 使い方全般 » カスタム投稿のページャーの表示

  • 解決済 mizugamiyuki

    (@mizugamiyuki)


    質問失礼します。

    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/記事のタイトル

    ページャーを正常に表示させる方法をご存知の方がいらっしゃいましたらご教授お願いいたします。

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • ishitaka

    (@ishitaka)

    こんにちは

    以下の2点が気になりました。

    single-samplecat.phpを作り下記を記述しています。

    カスタム投稿タイプ名が sample なので、single-sample.php ではないでしょうか。

    previous_post_link(‘%link’,’前の記事’,true,”,’samplecat’);
    next_post_link(‘%link’,’次の記事’,true,”,’samplecat’);

    register_taxonomy では sample_cat となっているので、

    previous_post_link( '%link', '前の記事', true, '', 'sample_cat' );
    next_post_link( '%link', '次の記事', true, '', 'sample_cat' );

    ではないでしょうか。

    nobita

    (@nobita)

    こんにちは、

    試してはいませんが、

    
    <div class="paging-column">
    <?php the_posts_pagination(); ?>
    </div>
    

    では、動きませんか?

    トピック投稿者 mizugamiyuki

    (@mizugamiyuki)

    ishitaka様
    nobita様

    ご回答ありがとうございます。

    ishitaka様のおっしゃる通りで、

    single-sample.phpを作りページネーションのパラメータをsample_catでsamplecatのページネーションの解決ができました!

    ありがとうございました!
    次はsamplecatの一覧表示をしたいので頑張って模索してみます!

    ありがとうございました!

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「カスタム投稿のページャーの表示」には新たに返信することはできません。