我有一个Wordpress网站,我有一个图库和每个项目的网址列出的图库。但是我似乎无法将foreach语句结合起来。我总是得到错误。我知道我很亲密,我想我只需要重新安排一下。谢谢!
<?php
foreach($latest_projects as $post) : setup_postdata($post);
//get image
$recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
foreach ($categories as $cat ) :
//get image
$categories = get_terms('gallery_cats');
?>
<li><a href="https://website.com/<?php echo $cat->slug; ?>"><img src="<?php echo $recent_project_thumb[0]; ?>" alt="<?php the_title(); ?>" width="162" height="100" class="imgstyle" /></a></li>
<?php endforeach; ?>
答案 0 :(得分:0)
你只有一个关闭的foreach声明。除此之外,代码看起来不错。我会做一些更好的缩进,以便你可以看到。
<?php
foreach($latest_projects as $post) : //begin post foreach
setup_postdata($post);
//get image
$recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
foreach ($categories as $cat ) : //begin categories foreach
//get image
$categories = get_terms('gallery_cats');
?>
<li>
<a href="https://website.com/<?php echo $cat->slug; ?>">
<img src="<?php echo $recent_project_thumb[0]; ?>" alt="<?php the_title(); ?>" width="162" height="100" class="imgstyle" />
</a>
</li>
<?php endforeach; ?> //end categories foreach
<?php endforeach; ?> //end post foreach