将数组打印为无序列表

时间:2012-03-20 18:41:37

标签: arrays wordpress meta-boxes

我正在使用Bill Erickson Custom Meta Boxes and Fields for WordPress并想知道如何将一系列复选框打印为无序列表。

这就是我在主题的functions.php文件中所拥有的:

array(
'name' => 'Other Features',
'desc' => 'field description (optional)',
'id' => $prefix . 'other_features',
'type' => 'multicheck',
'options' => array(
    'language' => 'English Speaking',
    'furniture' => 'Modern & Classic Furniture',
    'fridge' => 'Fridge/Freezer',
    'stove' => 'Wood Burning Stove',
    'oven' => 'Electric Oven',
    'internet' => 'Free Wi-Fi',
    'tv' => 'Television/DVD Player',
    'plugs' => 'UK Power Plugs',
)
),

这就是它在我的“添加/编辑”页面面板中的显示方式: enter image description here

我想知道该怎么办只打印选中的复选框作为带有ID的无序列表,如下所示:

<ul>
    <li id="language">English Speaking</li>
    <li id="furniture">Modern &amp; Classic Furniture</li>
    <li id="stove">Wood Burning Stove</li>
    <li id="oven">Electric Oven</li>
    <li id="internet">Free Wi-Fi</li>
    <li id="tv">Television/DVD Player</li>
</ul>

任何帮助我指向正确方向的人都将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:0)

这是我最终使用的,比尔埃里克森自己提供的:

<?php
global $post;
$other_features = get_post_meta( $post->ID, 'other_features' );
echo '<ul>';
foreach( $other_features as $id => $value )
    echo '<li id="' . $value . '">' . $value . '</li>';
echo '</ul>';
?>
相关问题