如何在短代码中使用选项树中的列表项元

时间:2016-09-26 12:23:43

标签: php wordpress

我正在练习wordpress。我想得到列表项元值。我为此使用选项树。基本上它通常在我在页面中查询时工作。但我想在短代码中使用它。下面是我的短代码函数和列表项元值反向函数

add_shortcode('features', 'features_area');
function features_area($atts){
extract( shortcode_atts( array(
    'title' => '',
    'simple_text_about_area' => '',
), $atts, 'features' ) );

$q = new WP_Query(
    array( 'posts_per_page' => '6', 'post_type' => 'features', 'order' => 'asc')
    );
$list = '';

$j = 0;

while($q->have_posts()) : $q->the_post();
    $j++;
    //get the ID of your post in the loop
    $idd = get_the_ID();

    $features_lists = get_post_meta($idd, 'features_accordion', true);          
    $content = apply_filters( 'the_content', get_the_content() );
    $feature_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($idd), 'feature-image' );
    $default_image = trailingslashit(get_stylesheet_directory_uri()) . 'img/mac.png';

    $feature_image_url = ! empty($feature_image_url[0]) ? $feature_image_url[0] : $default_image;

    $list .= '<div class="col-md-12 col-xs-12 col-sm-12 col-lg-12">
                <div class="single-option row">
                    <div class="col-md-6 col-sm-12 col-xs-12 col-lg-6 text-center">
                        <div class="choose-monitor wow fadeIn">
                            <img src="'.$feature_image_url.'" alt="">
                        </div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12 col-lg-6 ">
                        <div class="choose-options wow fadeIn">
                            <div class="panel-group" id="accordion-'.$j.'">
                                '.features_meta_list().'
                            </div>
                            </div>
                        </div>
                    </div>
                </div> ';        
endwhile;
$list.= '';
wp_reset_query();
return $list;  }





  function features_meta_list(){
 /* get the array */
    ob_start();


    $i=1;
foreach($features_lists as $features_list ) {
    $i++;

  echo '<div class="panel">
            <div class="panel-heading">
                <h4 class="panel-title">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-'.$j.'" href="#collapse'.$i.$j.'">
              '.$features_list['title'].' <i class="indicator fa fa-angle-down  pull-right"></i>
            </a>
          </h4>
            </div>
            <div id="collapse'.$i.$j.'" class="panel-collapse collapse">
                <div class="panel-body">
                    '.$features_list['desc'].'
                </div>
            </div>
        </div>';
}
return ob_get_clean();   }

当我使用它时它给我一个错误[为foreach()提供的无效参数..]。请问如何解决这个问题。有人可以帮忙吗?

提前致谢

0 个答案:

没有答案