サポート » 使い方全般 » カスタム投稿を固定ページに表示する方法を教えてください

  • 解決済 woman1986

    (@woman1986)


    カスタム投稿タイプというものを使って、現在固定ページにブログページを作るべく奮闘中です。

    function.phpに以下のコードを書き、投稿画面は作成できました。

    ———————————————–
    <?php

    add_action( ‘init’, ‘create_post_type’ );
    function create_post_type() {
    register_post_type(‘blog’,
    array(
    ‘labels’ => array(
    ‘name’ => __( ‘blog’ ),
    ‘singular_name’ => __( ‘店長のブログ’)
    ),
    ‘public’ => true,
    ‘has_archive’ => true,
    ‘menu_position’ => 5,
    )
    );
    }
    ?>
    ———————————————–

    これを固定ページで表示するにはどうしたらいいのでしょうか。。。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • (一覧を表示するのであれば)
    私はこのようにしました↓

    <?php
    $args = array(
    	'post_type' => 'camp_item_mainte', /* 投稿タイプ */
    	'posts_per_page' => 10,
    	'paged' => $paged,
    );
    $the_query = new WP_Query( $args );
    if ($the_query->have_posts()) :
    	while ($the_query->have_posts()) : $the_query->the_post(); /* ループ開始 */
    ?>
    <div id="post-<?php the_ID();?>" class="post section">
    	<h4><a href=" <?php the_permalink(); ?>">
    		<?php the_title(); ?>
    		</a>
    	</h4>
    	<?php
    		 $more = false;
    		 the_content('',FALSE,'');
    		 $more = true;
    	?>
    	<a class="more-link" href="<?php the_permalink(); ?>">続きを読む>></a>
    </div>
    <?php endwhile; // 繰り返し処理終了
    else : ?>
    <div class="post">
    	<h4>記事はありません</h4>
    	<p>お探しの記事は見つかりませんでした。</p>
    </div>
    <?php endif; ?>

    ※ただし、固定ページで一覧を表示させる場合、ページングがうまくいかなくて苦労しました。
    アーカイブページを作った方が得策とは思います。

    モデレーター gatespace

    (@gatespace)

    'has_archive' => true,
    なら、すでにアーカイブができていると思いますが。

    http://example.com/?post_type=blog
    で表示されませんか?

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「カスタム投稿を固定ページに表示する方法を教えてください」には新たに返信することはできません。