我不知道我做错了什么。一切正常。但我在第页收到警告
Warning: Invalid argument supplied for foreach() in /public_html/wp/xtheme/wp content/themes/tab.php on line 31
这是tab的短代码。foreach循环的这个问题
$arr = get_post_meta($post->ID, \'tab_details\',true);
foreach ($arr as $part){....}
function tab_shortcode($atts) {
extract(shortcode_atts(array(
\'category\' => \'\',
), $atts, \'tab_shortcode\'));
$q = new WP_Query(
array(\'posts_per_page\' => \'3\', \'orderby\' => \'menu_order\', \'order\' => \'DESC\', \'post_type\' => \'post_tab\',)
);
global $post;
$list = \'
<ul class="buttons-tab">
\';
while ($q->have_posts()) : $q->the_post();
$tab_id = get_the_ID();
$list .= \'<li><a href="#\' . $tab_id . \'">\' . get_the_title() . \'</a></li>\';
endwhile;
$list.= \'
</ul>
<div class="tab-content" id="tab">\';
while ($q->have_posts()) : $q->the_post();
$tab_id = get_the_ID();
$arr = get_post_meta($post->ID, \'tab_details\',true);
$tab_item = \'\';
foreach ($arr as $part) {
$tab_item .= \'<div class="text-icon-left">
<span class="iconCircle fa \' . $part[\'icon\'] . \'"></span>
<div class="text">
<p>\' . $part[\'text\'] . \'</p>
</div>
</div>\';
}
$list .= \'
<div class="item tab-pane" data-hash="\' . $tab_id . \'">\' . $tab_item . \'</div>\';
endwhile;
$list.= \'
</div>
\';
wp_reset_query();
return $list;
}
add_shortcode(\'tab\', \'tab_shortcode\');
选项卡显示良好,但此警告显示在页面上。