您可以使用get_pages
获取所有已发布的页面,类似于get_posts
, 像
<?php $args = array(
\'sort_order\' => \'asc\',
\'sort_column\' => \'post_title\',
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => \'\',
\'meta_key\' => \'\',
\'meta_value\' => \'\',
\'authors\' => \'\',
\'child_of\' => 0,
\'parent\' => -1,
\'exclude_tree\' => \'\',
\'number\' => \'\',
\'offset\' => 0,
\'post_type\' => \'page\',
\'post_status\' => \'publish\'
);
$pages = get_pages($args); // get all pages based on supplied args
foreach($pages as $page){ // $pages is array of object
$page_template = get_post_meta($page->ID, \'_wp_page_template\', true); // Page template stored in "_wp_page_template"
echo $page_template;
}
?>
签出这些链接以了解更多详细信息:
获取页面:https://codex.wordpress.org/Function_Reference/get_pages
获取页面模板:https://codex.wordpress.org/Function_Reference/get_page_template