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.

How can I change the for loop below so that I can assign the array's "key" value as the "value" for each input instead of the array's "option" value as I'm now doing (I still want to echo the array's "option" value as the label)?

$myradiooptions = array("grid1" => "Grid View (default)", "list1" => "List View (1 column)", "list2" => "List View (2 column)" );

$options = array (
array( "name" => "My Theme Options","type" => "title"), array( "type" => "open"),

array(  "name" => "Category Layout",
     "desc" => "description goes here",
     "id" => "my_category_layout",
     "type" => "radio",
    "options" => $myradiooptions ),

    ...etc}

//switch, case "radio":
?>
<li class="section">
    <label class="left" for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    <?php $count=1;foreach ($value['options'] as $option) { ?>
    <input type="radio" name="<?php echo $value['id']; ?>" id="<?php echo $count; ?>" value="<?php echo $option; ?>" <?php checked($option, get_settings($value['id'])); ?>/><label style="color:#666; margin:0 20px 0 5px;" for="<?php echo $count; ?>"><?php echo $option; ?></label>
  <?php $count++;} ?>
    <label class="description" style="margin-top:-5px;"><?php echo $value['desc']; ?></label>
</li>
<?php
break;
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If I am understanding you correctly just change

<?php $count=1;foreach ($value['options'] as $key => $option) { ?>

and you can access the key from $key.

share|improve this answer
    
exactly what I was looking for. I also had to change the checked to checked($key, get_settings($value['id'])); Thanks! –  Scott B Jan 24 '11 at 16:38
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.