从自定义主题选项中拉出滑块数据时出错

时间:2013-09-11 10:49:41

标签: php html wordpress

我正在尝试使用下面的代码从我的自定义主题选项面板中获取滑块数据。这将返回以下错误

警告:/ home / muratgok / public_html / wp-content / themes / default / page中的foreach()提供的参数无效 - 第16行的clients.php

我猜我的语法不完全正确,但我很难看到哪里。谢谢

        <?php echo $slides = $smof_data['example_slider']; //get the slides array

        foreach ($slides as $slide) {
            echo $slide['title'];
            echo $slide['url'];
            echo $slide['link'];
            echo $slide['description'];
        }

        ?>

下面的主题选项代码

$of_options[] = array(  "name"      => "Slider Options",
                        "desc"      => "Unlimited slider with drag and drop sortings.",
                        "id"        => "example_slider",
                        "std"       => "",
                        "type"      => "slider"
                );

1 个答案:

答案 0 :(得分:1)

尝试并确保它是一个数组$ smof_data ['example_slider']:

    <?php $slides = $smof_data['example_slider']; //get the slides array

    foreach ($slides as $slide) {
        echo $slide['title'];
        echo $slide['url'];
        echo $slide['link'];
        echo $slide['description'];
    }

    ?>