WordPress的 - 孩子
问题描述:
我使用WordPress插件的显示阵列数据 - advanced custom field,想表现出孩子的数组,这里是我的代码:WordPress的 - 孩子
我使用此代码显示自定义字段从一个特定的页面ID的儿童的数据:
<?php $args = array(
'depth' => 0,
'child_of' => 411);
$pages = get_pages(array('child_of'));
foreach($pages as $post)
{
setup_postdata($post);
$fields = get_fields();
if($fields->company_name != "") : ?>
<h2><?php echo $fields->company_name; ?></h2>
<?php else : ?>
<?php endif; ?>
<?php
}
wp_reset_query();
?>
这是我使用的显示页面本身的复选框数据(即它不是一个父/子)代码:
<?php $catNames = array('branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');
foreach($catNames as $name){
if(in_array($name, get_field('categories'))){
echo '<a href="/tags/design/'.$name.'" title="'.$name.'">'.ucwords($name).'</a>';
}
}
?>
我想要com把两个盒子放在一起,在第一个代码框的H2标签下面我想显示孩子的复选框数据,这怎么办?
更新: 当我将复选框代码添加到子代码时,我无法获取要显示的数据,它可能是空白或有错误。
这是我的页面working on。第一个缩略图已经被硬编码,第二个和第三个缩略图应该用上面的代码来获取标签,但是它没有。
答
这将返回勾选复选框:
echo implode(', ',get_field('categories'));
有什么错误? – Swift 2011-05-17 15:22:46
我已将代码放入,但目前没有显示任何内容。我猜测它没有选择生成页面411子代码的代码,因为它们没有与正确的变量链接在一起。 – Rob 2011-05-17 15:24:30