2
我在頁面內輸出一堆自定義帖子類型。如何獲取當前頁面中的所有帖子的標題?在wordpress中的頁面中獲取所有自定義帖子類型的標題
我在頁面內輸出一堆自定義帖子類型。如何獲取當前頁面中的所有帖子的標題?在wordpress中的頁面中獲取所有自定義帖子類型的標題
您應該查看WP_Query()以輸出自定義帖子類型。下面的代碼獲取所有類型爲「custom_post_type」的自定義帖子,將它們放入一個名爲$ loop的變量中,並遍歷它,輸出其中包含的每個帖子的標題。
<?php
// Get the 'Profiles' post type
$args = array(
'post_type' => 'custom_post_type',
);
$loop = new WP_Query($args);
while($loop->have_posts()): $loop->the_post();
the_title();
endwhile;
wp_reset_query();
?>
還有其他的參數可以傳遞給WP_Query()以使它更適合您的需求。文檔可以在here找到。
前右「的循環」,你可能也只是使用:
<?php query_posts('post_type=your_custom_post_type');?>
你指定一個獨立的領域他們的頭銜?如果沒有,你應該可以使用native:the_title()。您是否在創建自定義帖子類型時啓用了title屬性? – vtacreative 2013-03-19 19:19:47