2014-04-28 74 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類職位的意見。

相關問題