2016-01-26 62 views
0

我想添加評論框comments_template();上的自定義帖子,但不知道爲什麼它不來?請看下面的代碼,讓我知道我在做什麼錯誤?WordPress的評論框不是在自定義帖子上

<?php 
$temp = $wp_query; $wp_query= null; 
$wp_query = new WP_Query(); $wp_query->query('showposts=1' . '&paged='.$paged); 
while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 

    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> 
    <div> 
    <?php if (has_post_thumbnail()) : ?> 
     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
      <?php the_post_thumbnail(); ?> 
     </a> 
    <?php endif; ?> 
    </div> 
    <?php the_content(); ?> 
    <?php endwhile; ?> 
    <?php comments_template(); ?> 


<?php if ($paged > 1) { ?> 

<nav id="nav-posts"> 
    <div class="prev"><?php next_posts_link('PREVIOUS POSTS'); ?></div> 
    <div class="next"><?php previous_posts_link('NEXT POSTS'); ?></div> 
</nav> 

<?php } else { ?> 

<nav id="nav-posts"> 
    <div class="prev"><?php next_posts_link('PREVIOUS POSTS'); ?></div> 
</nav> 
+0

你在支持添加 '意見' 時,寄存器自定義後類型? –

+0

你的主題根文件夾中是否有「comments.php」文件? –

+0

@ Atif Tariq:感謝您的快速回復。我沒有主題根文件夾中的comments.php文件。評論框未通過不同的代碼風格註冊自定義帖子類型即可。由於頁面導航,我不得不改變代碼風格。 –

回答

0

註冊自定義文章類型就像這樣:

$args = array(
      'menu_icon'   => 'dashicons-format-video', 
      'labels'    => $labels, 
      'public'    => true, 
      'publicly_queryable' => true, 
      'show_ui'   => true, 
      'show_in_menu'  => true, 
      'query_var'   => true, 
      //'rewrite'   => array('slug' => 'book'), 
      'capability_type' => 'post', 
      'has_archive'  => true, 
      'hierarchical'  => false, 
      'menu_position'  => null, 
      'supports'   => array('title', 'editor', 'comments') 
     ); 
     register_post_type('custom_type', $args); 
相關問題