为多个 HTML 页面组织通用头部的不同方法有哪些? [关闭]

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

对于多个页面,如主页、产品页面等,如何组织每个页面的头部,因为

<head>
标签中的某些元素在所有页面中都是通用的,但有些元素需要添加到
 <head>
标签取决于具体页面。

我有多个页面,每个页面都需要指向图标的链接。但是,像特定于页面的样式表之类的东西不应该在通用的

<head>
标签中。请参阅下面的代码示例,了解我目前组织
<head>
标签的方式。

<!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
看起来像这样:

<meta charset="utf-8">
<title>Title</title>
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
<link rel="stylesheet" type="text/css" href=<?php echo "/css/include/header.css" ?>>
<link rel="stylesheet" type="text/css" href=<?php echo "/css/include/footer.css" ?>>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto&display=swap">
<link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/2dea6f9f6d.js" crossorigin="anonymous"></script>

因为我不希望这是一个基于意见的问题,我想知道还有哪些其他常用方法可以用纯 HTML 组织它?

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