2016-01-26 63 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); 
相关问题