Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

$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!

share|improve this question
add comment

2 Answers 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...

share|improve this answer
    
@AmbitiousAmoeba: If you have a good tutorial give me a link. Your solutions doesn't work. I have an error on pages: Warning: implode() [function.implode]: Invalid arguments passed in Z:\home\mysite.net\www\wp-content\themes\dddd\content.php on line 21 –  Denis Belousov Dec 19 '10 at 14:45
    
add a line with print_r($exclude); before wp_list_pages and post here what you see –  onetrickpony Dec 19 '10 at 14:50
    
@AmbitiousAmoeba: Nothing is happen. All still on the same place. –  Denis Belousov Dec 19 '10 at 15:20
    
well the problem is that you don't know the option name :) try replacing in my code 'src_excludepage' with 'src_excludepage_512' (the one from you db screenshot). also do a print_r so we can see if it's really a array... –  onetrickpony Dec 19 '10 at 15:29
    
@AmbitiousAmoeba: Now they show true, like in db for options name. I think instead true must be pageID and options name must be without numbers only src_excludepage. –  Denis Belousov Dec 19 '10 at 15:41
show 15 more comments

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.

share|improve this answer
    
+1, altough the themeshaper code could also be improved, but it's much better than OP's tutorial source –  onetrickpony Dec 19 '10 at 16:10
    
Yes, totally agree, but there's really not many good examples to be found, that's the best i've found that keeps the information short and sweet(to the point). I'd love to see a better example for themes, i couldn't find one (search terms are too general for this kind of information) from some brief searching. –  t31os Dec 19 '10 at 16:28
    
Thank you for the link. Yes it's much better when uses a single option but to many work need to made for implement this options. clark-technet.com/2010/01/… -Maybe this much better? –  Denis Belousov Dec 19 '10 at 16:50
    
Unfortunately that approach also uses several options(ie. not singular).. again looks like it's based of the same code as the previous site you linked to. –  t31os Dec 19 '10 at 17:01
    
ok, first thing, using a array with fields like "textarea", "checkbox" etc.., then using foreach(type...) is ridiculous :) The theme options need to be flexible. You may want to add text, images above, or below a certain option... Try my example from the linked question and after you implement that for your site I can help you add a option that uses multiple checkboxes. And you'll see how easy and little code it uses... –  onetrickpony Dec 19 '10 at 17:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.