我的foreach PHP中的问题
这是我的问题,我必须在如下图片下显示数组值(说明): 相反,它看起来是这样的 我正在解决这个问题,这是我当前的代码:我的foreach PHP中的问题,php,wordpress,foreach,Php,Wordpress,Foreach,这是我的问题,我必须在如下图片下显示数组值(说明): 相反,它看起来是这样的 我正在解决这个问题,这是我当前的代码: if (preg_match_all('/<div id="description" class="description">([^<]*)<\/div>/', $content, $match)) { for( $i = 0; $i < count($match[0]); $i = $i
if (preg_match_all('/<div id="description" class="description">([^<]*)<\/div>/', $content, $match)) {
for( $i = 0; $i < count($match[0]); $i = $i+1 ) {
$description[] = $match[0][$i];
}
}
$attachments =& get_children($args);
$arrayMatches = array();
if ($attachments) {
foreach(array_chunk($attachments, 2) as $img) {
echo '<div class="two_cols">';
foreach($img as $attachment) {
foreach($attachment as $attachment_key => $attachment_value) {
$imageID = $attachment->ID;
$imageTitle = $attachment->post_title;
$imagearray = wp_get_attachment_image_src($attachment_value, $size, false);
$imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true);
$imageURI = $imagearray[0]; // 0 is the URI
$imageWidth = $imagearray[1]; // 1 is the width
$imageHeight = $imagearray[2]; // 2 is the height
?>
<div class="col_1_2">
<div id="attachment_<?php echo $imageID; ?>" class="wp-caption alignnone" style="width: 356px;">
<a rel="lightbox-0" href="<?php echo $imageURI; ?>"><img class="wp-image-<?php echo $imageID; ?> size-full" title="<?php echo $imageTitle; ?>" src="<?php echo $imageURI; ?>" alt="<?php echo $imageAlt; ?>" width="456" height="304" /></a>
<p class="wp-caption-text"><?php echo $imageTitle; ?></p>
<?php
$arrayMatches[] = $match[0][$j];
?>
</div>
</div>
<?php
break;
}
$j++;
}
foreach(array_chunk($arrayMatches, 2) as $desc) {
echo '<div class="description">';
foreach($desc as $item) {
echo $item;
}
echo '</div>';
}
echo '</div>';
}
}
if(preg_match_all(')/([^Try:
foreach(数组块($arrayMatches,2)为$k=>$desc){
如果($k<1)继续;
回声';
foreach($desc作为$item){
echo$项目;
}
回声';
}
使这种显示变得简单。它不起作用,只显示最后两个描述
foreach(array_chunk($arrayMatches, 2) as $k => $desc) {
if($k < 1) continue;
echo '<div class="description">';
foreach($desc as $item) {
echo $item;
}
echo '</div>';
}