2014-04-28 125 views
0

我只想在我的WordPress网站上显示其中一个类别的评论。因此,例如我的梨类别的帖子将有一个评论功能可用,但在我的橙色页面评论部分将被禁用。在不同类别上显示评论

有什么建议吗?

回答

0

content.php文件更改:

<?php if (comments_open()) : ?> 
<div class="comments-link"> 
    <?php comments_popup_link('<span class="leave-reply">' . __('Leave a reply', 'twentytwelve') . '</span>', __('1 Reply', 'twentytwelve'), __('% Replies', 'twentytwelve')); ?> 
</div><!-- .comments-link --> 
<?php endif; // comments_open() ?> 

<?php 
$postid = get_the_ID(); 
$category = get_the_category($postid); 
$category = $category[0]->cat_name; 
if ($category == "Pear") 
{ 
    if (comments_open()) : ?> 
     <div class="comments-link"> 
     <?php comments_popup_link('<span class="leave-reply">' . __('Leave a reply', 'twentytwelve') . '</span>', __('1 Reply', 'twentytwelve'), __('% Replies', 'twentytwelve')); ?> 
     </div><!-- .comments-link --> 
    <?php endif; // comments_open() 
} 
?> 

,并在comments.php文件更改:

<?php if (have_comments()) : ?> 

<?php 
    $postid = get_the_ID(); 
$category = get_the_category($postid); 
$category = $category[0]->cat_name; 
if ($category == "Pear") 
    { 
     if (have_comments()) : 
?> 

变化:

<?php endif; // have_comments() ?> 
<?php comment_form(); ?> 

<?php endif; // have_comments() ?> 
<?php comment_form(); 
} 
?> 

上面只显示那些在Pear类职位的意见。

相关问题