在 WordPress 中组合 foreach 语句
我有一个 Wordpress 网站,并且有一个画廊,其中列出了每个项目的图像和 url。但是我似乎无法合并 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; ?>
I have a Wordpress website and I have a gallery listed with an image and url for each item. However I can't seem to combine the foreach statements. I always get errors. I know I am close, I think I just need to re-arrange things a bit. Thank you!
<?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; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你只有一个 foreach 结束语句。除此之外,代码看起来不错。我会做更好的缩进,以便您可以看到。
you only have one closing foreach statement. Other than that the code looks good. I would do a little better indenting so that you can see.