我正在使用设置API构建一个主题选项页面。一切都很好,但我现在我想创建一个用页面填充的下拉列表,我不知道怎么做!
例如,我有一段显示页面列表的代码,但当我选择一个页面并在保存时单击时,所选页面不会被保存!
function combo_select_page_callback() {
$options = get_option(\'journal_theme_blog_2_col\');
echo "<select name=\'select_page\'>
<option value=\'\'>";
echo esc_attr( __( \'Select page\' ) ); ?></option>
<?php
$pages = get_pages();
foreach ( $pages as $page ) {
$selected = \'<option value="\' . get_page_link( $page->ID ) . \'">\';
$selected .= $page->post_title;
$selected .= \'</option>\';
echo $selected;
}
echo \'</select>\';
}// end combo_select_page_callback
谢谢你的帮助,尼尔森
最合适的回答,由SO网友:naires 整理而成
我找到了解决办法。我使用了wordpress函数wp_dropdown_pages
<?php function combo_select_page_callback() {
$options = get_option(\'function plugin\');
wp_dropdown_pages(
array(
\'name\' => \'function plugin[ID used to identify the field throughout the theme]\',
\'echo\' => 1,
\'show_option_none\' => __( \'— Select —\' ),
\'option_none_value\' => \'0\',
\'selected\' => $options[\'ID used to identify the field throughout the theme\']
)
);
} ?>