我想寫一個自定義帖子類型的條件查詢。我需要它與某個特定的帖子相關。因此,舉例來說,我目前的代碼對所有項目的工作:自定義帖子類型有條件的 - WordPress的
<?php if ('project' == get_post_type()) { ?>
// Get content
<?php } ?>
不過,我需要能夠與ID 75.指定某個項目這可能嗎?
任何幫助,非常感謝。
乾杯,
我想寫一個自定義帖子類型的條件查詢。我需要它與某個特定的帖子相關。因此,舉例來說,我目前的代碼對所有項目的工作:自定義帖子類型有條件的 - WordPress的
<?php if ('project' == get_post_type()) { ?>
// Get content
<?php } ?>
不過,我需要能夠與ID 75.指定某個項目這可能嗎?
任何幫助,非常感謝。
乾杯,
可以使用內循環get_the_ID()
功能:
http://codex.wordpress.org/Function_Reference/get_the_ID
<?php if ('project' == get_post_type() && get_the_ID() == 75) { ?>
// Get content
<?php } ?>
您可以使用$後全局變量爲特定的自定義職位。
<?php if($post->post_type == 'project' && $post->ID == '75') : ?> //Get Content <?php endif; ?>
if($post->post_type == 'type your post type here') :
//Get Content
ENDIF;
這是工作...
你能解釋爲什麼嗎? – Trudbert 2014-08-27 09:15:18