Add a series of checkboxes to theme options

Hi I made a theme options by this tutorial

This options have multicheck type by checkboxes. I don’t know how to make it work. I’m try to exclude page using this multicheck.
This is my array with options:

Read More
$pages = get_pages('sort_column=post_parent,menu_order');
$pageids = array();
    foreach ($pages as $page) {
        $pageids[$page->ID]= $page->post_title;
    }
array( "name" => "Exclude page",
        "desc" => "",
        "id" => $shortname."_excludepage",
        "type" => "multicheck",
        "options" => $pageids,
        "std" => ""),

This screen show how this function looks in my DB:

http://i.stack.imgur.com/QFwV7.png

512 is the ID of a page that I try to exclude.

Look’s like this in admin:

http://i.stack.imgur.com/31TQa.png

In my template I’ve use this standart method for exclusion:

wp_list_pages("exclude=get_option('src_excludepage'));

Please help me with this function! Thank you!

Related posts

Leave a Reply

2 comments

  1. Want some honest advice? Work from a better code base..

    Though, it’s not your fault, there are hundreds of blogs with variations of similar code, i’m not sure where it originated, but i see similar code “alot”…

    If you can get by without the hand holding and just manage with a good code base, i’d suggest the following..

    http://themeshaper.com/sample-theme-options/

    It’s not the most fancy or advanced example, but the approach is sound, it only uses a single option to store all the values and also uses the settings api for handling options.

  2. Assuming your back-end works, and you can check multiple fields, and that the field values are really stored as an array, use:

    $exclude = get_option('src_excludepage');
    wp_list_pages(array(
          "exclude" => implode(',', $exclude['options']),
       ));
    

    PS: the tutorial you use has a pretty weird way of handling “multicheck”. A much easier method is to append [] to the checkbox input names…

    Update:

    in the mytheme_admin() function add another case:

     case "page_multicheck":
      option_wrapper_header($value);
    
      $pages = get_pages('sort_column=post_parent,menu_order');
      $pageids = array();
      foreach ($pages as $page){
        $pageids[$page->ID] = $page->post_title;
    
        $input_id = $value['id'] . '_' . $page->ID;
        $checkbox_setting = get_settings($value['id']);
        if (in_array($page->ID, $checkbox_setting)) $checked = "checked="checked""; else $checked = "";
         ?>
         <input type="checkbox" name="<?php echo $value['id']; ?>[]" id="<?php echo $input_id; ?>" <?php echo $checked; ?> />
         <label for="<?php echo $input_id; ?>"><?php echo $page->post_title; ?></label
         ><br />
         <?php
      }
      option_wrapper_footer($value);
      break;
    

    in the $options array remove the old option and add:

      array("name" => "Exclude page",
            "desc" => "",
            "id" => $shortname."_excludepage",
            "type" => "page_multicheck",
            "options" => array(),
            "std" => ""),
    

    now, theoretically my code above should work…