如何为每个页面组织一个通用标题,以在纯 HTML 中展开?

问题描述 投票:0回答:0

我有多个页面,每个页面都需要一个样式表和其他链接。比如一个简单的主页:

<!DOCTYPE html>
<html lang="en">

<head>
    <?php include_once("include/head.php"); ?>
    <link rel="stylesheet" type="text/css" href=<?php echo "/css/home.css" ?>>
    <link rel="stylesheet" type="text/css" href=<?php echo "/css/include/product.css" ?>>
</head>

<body>
    <?php require_once("include/header.php"); ?>
    <main>
        <div class="class">
            <h2>Class</h2>
            <div class="items">
                <?php foreach ($data['products'] ? $data['products'] : [] as $product) {
                    include("include/product.php");
                } ?>
            </div>
        </div>
    </main>
    <?php require_once("include/footer.php"); ?>
</body>

</html>

我有一个通用的 head.php 并将元素添加到 HTML 的头部的方式是一个好习惯吗?是否有更好的做法来组织包括可变头标签到页面?

php html code-organization
© www.soinside.com 2019 - 2024. All rights reserved.