私は単純に仲間にして私のホームページにカスタムで追加したプロジェクトを表示しています。これらのコード行を使用してワードプレスで1つのカスタムポストタイプを表示できません
$args = array('post_type' => 'recent-projects', 'posts_per_page' => 10 ,'order' => 'ASC');
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
the_title();
echo get_post_permalink($post->ID, $leavename, $sample);
endwhile;
カスタムポストのpermalinkをクリックすると、インデックスページが表示されます。私もarchive.phpを持っています。 ここにはfunctions.phpのコードがあります。
register_post_type('recent-projects',
// CPT Options
array(
'labels' => array(
'name' => __('Recent Projects'),
'singular_name' => __('Recent Project')
),
'taxonomies' => array('recordings', 'category', 'whatever'), //add this....
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'recent-projects'),
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',)
)
);
と、これはアーカイブ最近-projects.php
<?php get_header(); ?>
<div class="content-area">
<div class="container main_content_wrap">
<div class="page_wrapper">
<section id="site-main" class="site-main content-part" >
<div class="blog-post">
<h1 class="classic-title"><span>Recent Projects</span></h1>
<br>
<br>
<ul>
<?php
$args = array('post_type' => 'recent-projects','order' => 'ASC');
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();?>
<li>
<small><?php the_time('F jS, Y'); ?></small><br>
<strong>-</strong> <?php the_title(); ?><br> <a href="<?php the_permalink(); ?>">Read</a><br><br>
</li>
<?php endwhile; // end of the loop. ?>
</ul>
</div>
</section>
</div><!--end .page_wrapper-->
</div>
</div>
<?php get_footer(); ?>
ただのメモです。 '、$ leavename、$ sample'を' get_post_permalink'の中に追加する必要はありません。 – WizardCoder
これは<?php get_template_part( 'content'、 'single');あなたのカスタムポストタイプのループを出力していますか?もしそうなら、あなたの 'archive-recent-projects.php'テンプレートの' whileループ 'の外に移動してみてください。 – WizardCoder
@WizardCoder私はarchive-recent-projects.phpを更新しました。再度ご覧ください。 –