I'm pretty familiar with WordPress, and a fan of this CMS. So I'm used to the get_header()
function that includes the header.php
file. But now I'm developing a raw PHP project, and I want a similar ease here too. I designed a folder structure like below:
project/ css/ bootstrap.css js/ jquery.js project.js inner-folder/ some-page.php header.php index.php footer.php style.css
I made a custom function is_page()
just like WordPress to load page-specific items. Everything's working just fine where my header.php
contains:
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
...
and my footer.php
contains:
...
<script src="js/jquery.js"></script>
<script src="js/project.js"></script>
</body>
</html>
And my index.php
contains:
<?php require_once( 'header.php' ); ?>
...
<?php require_once( 'footer.php' ); ?>
And everything's working just fine, until...
I started working on the inner-folder/
. In some-page.php
I used the same code like the index.php
and you can guess, all the CSS and JS file links get broken.
How can I make a function or something so that regarding anywhere of my project
folder (within any sub directory or sub-sub directory) I can load any of my resources without any hamper? And it should be performance-savvy too.