teSo我正在尝试通过Magic Fields从重复组输出文本和图像字段,文本字段显示不同的重复项,但图像字段会反复显示第一个图像的URL。谁能告诉我我做错了什么?
<?php
$articlephotos="&w=728&h=560&q=95&zc=1&iar=0&far=0";
?>
<?php $myContents = get_group('contents'); // use the Custom Group name
foreach($myContents as $contents){ ?>
<?php if( get('contents_text', true) ) { ?>
<div class="contents"><?php echo $contents['contents_text'][1]; ?></div>
<?php } ?>
<?php if( get('contents_image', true) ) { ?>
<div class="post_container" style="padding-bottom: 24px;">
<div class="photo_outside">
<div class="photo_inside">
<img src="<?php bloginfo('stylesheet_directory'); ?>/phpThumb/phpThumb.php?src=<?php echo get_image('contents_image',$contents,$contents,0); ?><?php echo $articlephotos ?>" title="<?php echo get_the_title($ID) ?>" alt="<?php echo get_the_title($ID) ?>">
</div><!-- end photos_inside -->
</div><!-- end photos_outside -->
</div>
<?php } ?>
<?php } ?>
提前致谢!
编辑:Var Dump输出:
array(2){[1] =&gt; array(2){[“contents_text”] =&gt; array(1){[1] =&gt; string(1085)“
文字01
“} [”contents_image“] =&gt; array(1){[1] =&gt; array(2){[”original“] =&gt; string(122)“http://www.mysite.com/image01.jpg”[“thumb”] =&gt; string(122)“http://www.mysite.com/image01.jpg”}}} [2] =&gt;数组(2){ [ “contents_text”] =&GT; array(1){[1] =&gt; string(1380)“
文字02
“} [”contents_image“] =&gt; array(1){[1] =&gt; array(2){[”original“] =&gt; string(119)“http://www.mysite.com/image01.jpg”[“thumb”] =&gt; string(119)“http://www.mysite.com/image01.jpg”}}}}
我缩写了文本内容和图片网址。
答案 0 :(得分:1)
我找到了来自插件组的解决方案,感谢您的帮助!
<?php $elements = get_group('contents');
foreach($elements as $key => $element){
if( get('contents_text', true) ) {
echo '<div class="contents">';
echo $element['contents_text'][1];
echo '</div>';
}
$images = get_order_field('contents_text',$key);
foreach($images as $image){
if( get('contents_image', $key ,$image = true) ) {
echo '<div class="photo_outside"><div class="photo_inside">';
echo '<img src="' . get('contents_image', $key ,$image) .'">';
echo '</div></div>';
}
} } ?>