2013-08-03 55 views
0

我有一些數據只有在對帖子有一條或多條評論時纔會顯示。如果有0條評論,我想不顯示任何內容。WP評論計數PHP有條件

的邏輯是這樣的:

如果評論計數> 0 {做到這一點} 其他{}

如果有人可以幫助我用PHP代碼段爲這種類型的事情,將不勝感激。

回答

0
$nr_comments = get_comments_number($post_id); 

if($nr_comments > 0){ 
    //we have comments and do this 
} 
else{ 
    //we don't have any comments yet and do something else 
} 

注意:該標籤必須在循環內。

由於這是在循環中,你不需要$post_id

+0

我可能需要在循環外運行,也許在自定義查詢中,是否有另一種方法我應該使用它? – user1447958

+0

如果在循環之外給它一個帖子ID,它應該是它的工作。 –