Karl Friedchicken Karl Friedchicken - 7 months ago 10
PHP Question

how to create header php footer php or sidebar.php

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>




Answer

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>