是否可以从不同的文件夹源链接到header.php和footer.php?
我是PHP的初学者。 我有多个网页居住在不同的位置。因此,当我希望从不同文件夹中的网页链接到header.php和footer.php时,是否可以这样做?如图所示,我必须创建三个不同的文件夹,其中包含相同的文件header.php和footer.php,以便能够从三个不同的源链接。 致以最良好的问候是否可以从不同的文件夹源链接到header.php和footer.php?,php,dynamic,webpage,Php,Dynamic,Webpage,我是PHP的初学者。 我有多个网页居住在不同的位置。因此,当我希望从不同文件夹中的网页链接到header.php和footer.php时,是否可以这样做?如图所示,我必须创建三个不同的文件夹,其中包含相同的文件header.php和footer.php,以便能够从三个不同的源链接。 致以最良好的问候 为$h\u路径和$f\u路径动态赋值。 为$h\u path和$f\u path动态分配值。 我为没有提供有关这些问题的足够信息而道歉。我的问题是,当index.php分别通过“includes/h
为$h\u路径和$f\u路径动态赋值。
为$h\u path和$f\u path动态分配值。
我为没有提供有关这些问题的足够信息而道歉。我的问题是,当index.php分别通过“includes/header.php”和“includes/footer.php”引用页眉和页脚时,其他网页位于另一个文件夹中,需要通过“./includes/header.php”访问includes文件夹。引用这些文件时没有问题,但是当headers.php将其写入仅使用index.php时,当headers.php将其中的网页作为目标时会出现问题。例如,将只在index.php上工作,而不在需要的文件夹中的php文件上工作,但我将尝试使用$h_path='';和$f_path=''很快 我为没有提供有关这些问题的足够信息而道歉。我的问题是,当index.php分别通过“includes/header.php”和“includes/footer.php”引用页眉和页脚时,其他网页位于另一个文件夹中,需要通过“./includes/header.php”访问includes文件夹。引用这些文件时没有问题,但是当headers.php将其写入仅使用index.php时,当headers.php将其中的网页作为目标时会出现问题。例如,将只在index.php上工作,而不在需要的文件夹中的php文件上工作,但我将尝试使用$h_path='';和$f_path=''很快 是的,可以使用单个footer.php和单个header.php文件,并在需要时随时加载它们
我建议你可以创建一个include文件夹,然后在include文件夹中创建另一个名为common的文件夹,你可以在其中放置网站元素,这些元素在整个网站中始终相同,即页脚和页眉
然后,我还将在include中放置一个函数文件,我将在其中放置我的网站函数。此函数文件中包含一个函数,我将在任何时候使用header.php
和footer.php
文件时使用该函数
Functions.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
footer.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
页脚内容
&抄袭;网站名称
主要网站页面
您的主要网站页面是索引、关于、服务等页面
在这些页面中,您将加载函数文件,然后能够加载页眉和页脚
index.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
页面内容
关于页面
<?php
include 'includes/functions.php';
$meta = array(
'pagetitle' => 'About Us',
'pagedescription' => 'This is about page'
);
loadview('header',$meta);
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<!-- load footer -->
<?php
loadview("footer");
?>
页面内容
希望这能给你一个如何实现目标的想法,有很多方法可以实现
如果您需要任何帮助,请告诉我。是的,可以使用单个footer.php和单个header.php文件,并在需要时随时加载它们 我建议你可以创建一个include文件夹,然后在include文件夹中创建另一个名为common的文件夹,你可以在其中放置网站元素,这些元素在整个网站中始终相同,即页脚和页眉 然后,我还将在include中放置一个函数文件,我将在其中放置我的网站函数。此函数文件中包含一个函数,我将在任何时候使用
header.php
和footer.php
文件时使用该函数
Functions.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
footer.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
页脚内容
&抄袭;网站名称
主要网站页面
您的主要网站页面是索引、关于、服务等页面
在这些页面中,您将加载函数文件,然后能够加载页眉和页脚
index.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
页面内容
关于页面
<?php
include 'includes/functions.php';
$meta = array(
'pagetitle' => 'About Us',
'pagedescription' => 'This is about page'
);
loadview('header',$meta);
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<!-- load footer -->
<?php
loadview("footer");
?>
页面内容
希望这能给你一个如何实现目标的想法,有很多方法可以实现
如果您需要任何帮助,请告诉我是的,您可以在
主页中使用
和页脚
,将header.php
和footer.php
放在另一个名为“includes”的文件夹中,并在您的索引文件夹中写入以下代码的任何php文件。在文件开头添加头文件include_once(“../includes/header.php”)文件末尾的代码>包含页脚文件include_once(“../includes/footer.php”)
检查这个问题,这里已经回答了可能重复的Yes。您可以在主页中使用
和页眉.php
将和页脚.php
放在另一个名为“includes”的文件夹中,并在您的索引文件夹中写入下面代码的任何php文件。在文件开头添加头文件include_once(“../includes/header.php”)文件末尾的代码>包含页脚文件include_once(“../includes/footer.php”)代码>检查这个问题,这里已经回答了可能的重复问题