How to create a drop down list with pages to a themes options page?

I’m building a themes options page using settings API. Everything is ok, but i now i want to create a drop down list populated with pages and i don’t know how to!

For example, i have this piece of code that show the list of pages, but when i select a page and cick on save, the page selected doesn’t get saved!

Read More
    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

Thank for the help,
nelson

Related posts

Leave a Reply

1 comment

  1. I have found the solution. I used the wordpress function 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' => __( '&mdash; Select &mdash;' ),
                 'option_none_value' => '0',
                 'selected' => $options['ID used to identify the field throughout the theme']
            )
        );
    } ?>