html - how to create header php footer php or sidebar.php
Get the solution ↓↓↓Solution:
Just create the file header.php and use the get_header() function to include it in your index.php. To include your footer.php you can use the get_footer() function.
header.php
<!---Header--->
<ul class="navbar">
<li><a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a></li>
</ul>
footer.php
<!----footer--->
<footer class="w3-container w3-green">
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>
</footer>
index.php
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<?php get_header(); ?>
<main>Main content</main>
<?php get_footer(); ?>
</body>
</html>
Answer
Solution:
use php's include_once.
First, put your header and footer contents in a header.php and footer.php file.
Header.php
<ul class="navbar">
<li>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
</li>
</ul>
Footer.php
<footer class="w3-container w3-green">
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>
</footer>
Then in your main php files, let's say it's index.php, you can do it this way.
<!DOCTYPE HTML>
<html>
<head>
blablabla
</head>
<body>
<!--Header-->
<?php include_once 'path-to-header.php'; ?>
Another body contents
<!--Footer-->
<?php include_once 'path-to-footer.php'; ?>
</body>
</html>
Answer
Solution:
Create header.html and footer.html:
header.html:
<ul class="navbar">
<li><a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a>
<a href="#">navbar</a></li>
</ul>
footer.html:
<footer class="w3-container w3-green">
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>
</footer>
Whenever you want to include either of the two code in a portion of your code, paste the following:
For the header:
<?php require('header.php'); ?>
For the footer:
<?php require('footer.php'); ?>
Whenever you want to edit the style of your header/footer, just go into those files and create the styles you wish. Alternatively you can link a css file to the files.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.