0

I created a select metabox within my functions.php on Wordpress.

'fields' => array(
    array(
        'name' => 'CMS Logo',
        'id' => 'cms_icon_image',
        'type' => 'select',
        'options' => array(
            'Wordpress'   => 'Wordpress',
            'Magento'     => 'Magento',
            'OpenCart'    => 'OpenCart',
        )
    )               
)

I need to set an unique ID or Class for each select option. This will help to style each option( I will add an image with css for each option)

4

1 回答 1

0

好的,这是您正在寻找的东西:

<?php
$array = array(
        'name' => 'CMS Logo',
        'id' => 'cms_icon_image',
        'type' => 'select',
        'options' => array(
            'Wordpress'   => 'Wordpress',
            'Magento'     => 'Magento',
            'OpenCart'    => 'OpenCart',
        )
    ) ;

foreach ($array as $key => $value) {
    $array[] = $key;

    if (is_array($array[$key])) {
        $results = array_keys($array[$key]);
        echo "<select>";
        foreach ($results as $result => $val){
            echo "<option class='" . $val . "'>" . $val . "</option>";
        }
        echo "</select>";
    }
}
?>

这将输出一个选择框,其中包含<option>数组中定义的每个选项。

希望这可以帮助

于 2013-09-19T16:58:50.970 回答