2017-06-06 5 views
0

私は単純に仲間にして私のホームページにカスタムで追加したプロジェクトを表示しています。これらのコード行を使用してワードプレスで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(); ?> 
+0

ただのメモです。 '、$ leavename、$ sample'を' get_post_permalink'の中に追加する必要はありません。 – WizardCoder

+0

これは<?php get_template_part( 'content'、 'single');あなたのカスタムポストタイプのループを出力していますか?もしそうなら、あなたの 'archive-recent-projects.php'テンプレートの' whileループ 'の外に移動してみてください。 – WizardCoder

+0

@WizardCoder私はarchive-recent-projects.phpを更新しました。再度ご覧ください。 –

答えて

0

利用get_the_ID()代わりにget_post_permalinkため$post->IDという名前のファイル内のコードです。 $post->IDは現在のページのIDを取得しますが、あなたの場合はホームページです。

+0

いいえ、これは動作しませんでした –

0
$recent_posts = new WP_Query(array(
'post_type' => 'recent-projects', 
'posts_per_page' => 10 , 
'order' => 'ASC' 
)); 
if($recent_posts->have_posts()) : 
    while($recent_posts->have_posts()) : $recent_posts->the_post(); 
     echo '<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>'; 
     the_content(); 
    endwhile; 
endif; 
wp_reset_postdata(); 
+0

私はこのコードをarchive-recent-projects.phpに掲載しましたが、まだ動作していません。 –

関連する問題