2012-04-14 58 views
3

我想寫一個自定義帖子類型的條件查詢。我需要它與某個特定的帖子相關。因此,舉例來說,我目前的代碼對所有項目的工作:自定義帖子類型有條件的 - WordPress的

<?php if ('project' == get_post_type()) { ?> 
// Get content 
<?php } ?> 

不過,我需要能夠與ID 75.指定某個項目這可能嗎?

任何幫助,非常感謝。

乾杯,

回答

2

您可以使用$後全局變量爲特定的自定義職位。

<?php if($post->post_type == 'project' && $post->ID == '75') : ?> //Get Content <?php endif; ?>

1
if($post->post_type == 'type your post type here') : 
    //Get Content 

ENDIF;

這是工作...

+0

你能解釋爲什麼嗎? – Trudbert 2014-08-27 09:15:18

相關問題