php - 包括
endforeach 语句后的标记
问题描述
所以我希望能够<p></p>
在下面的 foreach 语句的末尾包含一个 using html 标签,但我一直遇到代码问题。
代码:
<?php if(!empty($mediaUrls)):
if(is_front_page() || is_home()):
$counter = 0;
foreach($mediaUrls as $entry):
$counter++;
$mediaurl = $entry['media_url'];
$permalink = $entry['permalink'];
if($counter > 6) {
break;
}
?>
<article class="tw-status">
<div class="tw-content">
<a href="<?= $permalink; ?>" target="_blank"><img alt="" class="insta_image" src="<?= $mediaurl; ?>" width="100%"/></a>
</div>
</article>
<?php endforeach;
endif;
else:
echo 'No posts available.';
endif;
?>
解决方案
您需要先关闭PHP
,然后才能添加P
标签,如下所示:
<?php if(!empty($mediaUrls)):
if(is_front_page() || is_home()):
$counter = 0;
foreach($mediaUrls as $entry):
$counter++;
$mediaurl = $entry['media_url'];
$permalink = $entry['permalink'];
if($counter > 6) {
break;
}
?>
<article class="tw-status">
<div class="tw-content">
<a href="<?= $permalink; ?>" target="_blank"><img alt="" class="insta_image" src="<?= $mediaurl; ?>" width="100%"/></a>
</div>
</article>
<?php endforeach; ?>
<p></p>
<?php
endif;
else:
echo 'No posts available.';
endif;
?>
希望它可以帮助你。
推荐阅读
- jestjs - 如何禁用 PhpStorm 在运行测试时创建的代码覆盖率文件夹?
- php - 如何从索引页面上的 url 获取用户名
- c# - 哪些地址用于网络?
- python - 通过重命名的“本地主机”连接到 postgres 时出错
- python - Pip3 在 docker build 期间无法安装 requirements.txt
- php - 如何从 postdata 中仅获取值可用的键数据数组?
- python - 使用涉及 HTML 的 Django 创建 AP 测验
- mongodb - mongodb 这个数据库没有启用分片,即使我确实连接到了 mongos
- node.js - Node JS 和 Sequelize 错误:在将标头发送到客户端后无法设置标头
- javascript - 为什么 d3 scaleTime 与其轴不匹配?