php - 在页脚中首先处理 HTML
问题描述
我有一个问题在我的页脚中,有部分 Html 和 PHP,然后又是 HTML。问题是在网站上,整个 HTML 都显示在 PHP 之前。你可以在下面的照片中看到它。
谢谢,JS
<footer class="row align-items-center block bg-light border-t-o">
<!-- Footer Titel -->
<div class="col-lg text-left footer-content">
<h1 class="sponsor">Sponsoren:</h1>
</div>
<!-- Sponsorenbilder -->
<?php
$random1 = rand(1,4);
$random2 = rand(1,4);
$random3 = rand(1,4);
$random4 = rand(1,4);
echo "
<div class='col-md text-center footer-content' style='order: " . $random1 . ";'>
<img class='img-fluid img-hover' src='images/footer/bsp.jpg' alt='Sponsor 1'></img>
</div>
<div class='col-md text-center footer-content' style='order: " . $random2 . ";'>
<img class='img-fluid img-hover' src='images/footer/bsp.jpg' alt='Sponsor 2'></img>
</div>
<div class='col-md text-center footer-content' style='order: " . $random3 . ";'>
<img class='img-fluid img-hover' src='images/footer/bsp.jpg' alt='Sponsor 3'></img>
</div>
<div class='col-md text-center footer-content' style='order: " . $random4 . ";'>
<img class='img-fluid img-hover' src='images/footer/bsp.jpg' alt='Sponsor 4'></img>
</div>
";
?>
<!-- Impressum Button -->
<div class="col-lg text-right footer-content">
<h1 class="impressum impressum-style"><a class="impressum-style" href="impressum.html">Impressum</a></h1>
</div>
</footer>
解决方案
如果我理解正确,问题不在于 PHP 实际上是第二个加载,而是 PHP 生成的实际代码块与代码流的位置不同。
这是因为给定order
样式的列实际上放置在没有顺序样式的列之后。
为了解决这个问题,您可以使用更多的 PHP 来确保第三块代码的顺序高于其他所有代码块。
<?php
function getHighest($list_of_numbers){
$highest = 0;
foreach($list_of_numbers as $list_item){
if ($list_item > $highest){
$highest = $list_item;
}
}
return $highest;
}
$highest = getHighest([$random1, $random2, $random3, $random4]) + 1;
echo "<div class='col-lg text-right footer-content' style='order: ${highest}'>"
?>
推荐阅读
- docker - docker-compose run 不会导致竞态条件?
- arrays - 如何在 Swift 的 UILabel 中插入 UITextField?
- javascript - 将查询过滤器应用于 JavaScript 对象数组
- suitecrm - 如何检查关系字段值正在变化
- r - 如何使用 r 通过使用列表从 url 迭代更新字符串来下载多个文件
- java - 如何格式化字符串以打印 4 位数字和 2 位小数
- sql - BigQuery,如何在 where 子句中使用别名?
- javascript - 如何通过流(以无损方式)将参数传递给函数?
- google-compute-engine - 使用 GCP 部署管理器更新映像
- python - Python 日期时间 1970-01-01 07:00:07