COMMON ELEMENTS PHP HTML NAVBAR

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
HTML5 
 1529  View(s)
Ratings:
Rate this:
Hi Everyone!

I am trying to make a template for my website. Basically taking out all the common stuff out using php's include function.

I have made a navigationbar.php and samplepage.php. navigationbar has all the links to stylesheets etc. When they are in the same folder and I include navigationbar.php in samplepage it works just fine.

However when i move samplepage.php to a subdirectory (leaving navigationbar.php in the same folder) and link navigationbar.php with the menu doesn't come formatted. it seems samplepage is getting contents from navigationbar.php but navigationbar is not linking to the css files.

Can anyone tell what I'm doing wrong here? i'm using xampp and have tried with both relative and absolute paths- (include '../navigation.php' and 'localhost/folder/navigation.php')

Thanks in advance!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: common elements php html navbar

    Hi Samuel!

    Try using something along the lines of this to link to your header/footer files:

    include($_SERVER['DOCUMENT_ROOT'].'/path_to/header.php');
    and then appropriately link to your .js/.css files within header.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!