Reputation: 53
ok. i want create a php file. i want make header.php footer.php. i need it because it will make me not tried to edit one by one in html. how to do that.? thank in advance answer soon ! :v
footer{ text-align:center; margin-top: 150px;}
ul{list-style-type: none;}
a {text-decoration: none; color: green;}
li a,li {padding: 0px 10px;}
<!---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--->
<footer class="w3-container w3-green">
<p>lorem ipsum lorem ipsum lorem ipsum lorem ipsum</p>
</footer>
Upvotes: 1
Views: 1639
Reputation: 7113
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.
Upvotes: 1
Reputation: 1816
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>
Upvotes: 1
Reputation: 73
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>
Upvotes: 1