Skip to main content
Make question title clearer
Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

How can Ito create a multiple choice radio group with multiple options and only one ID value?for a single theme option

Tweeted twitter.com/#!/StackWordPress/status/29084865144033280
Source Link
Scott B
  • 5.7k
  • 14
  • 94
  • 148

How can I create a radio group with multiple options and only one ID value?

Logically, I'm thinking it should something like...

<input type="radio" id="my_category_layout">
    <option value="Item1">Item 1</option>
    <option value="Item2">Item 2</option>
    <option value="Item3">Item 3</option>
</input>

But from what i've seen radio buttons dont markup like that.

My existing code is below that creates a select list pulldown menu that allows me to capture a selected value. I'm struggling with how to convert this into a radio group.

The main issue is that there is only one ID to represent the select, but I can't figure how to create three radio buttons with a single ID value that can be passed to represent the selected button.

How would I do that? Here's my existing code for creating a select with a single id and multiple values...

<?php
$mySelectOptions = array("list" => "List View", "grid1" => "Grid View Multi Column", "grid2" => "Grid View Two Column");

array(  "name" => "Category Layout",
     "desc" => "description goes here",
     "id" => "my_category_layout",
     "type" => "select",
    "options" => $mySelectOptions ),
?>
<form method="post">

<?php foreach ($options as $value) 
{
    switch ( $value['type'] ) 
    {
    case "select":
    ?>
    <select class="input" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
    <?php foreach ($value['options'] as $option) { ?>
        <option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"';
        } 
        elseif ($option == $value['std']) 
        { 
        echo ' selected="selected"'; 
        } ?> value='<?php echo $option; ?>'>
        <?php echo $option; ?></option><?php } ?>
    </select>
<?php
break;
case "radio":
?>