1

Web development newbie here. My site is becoming large enough that recently took a few steps to help manage it including:

  1. Using a separate header.php; footer.php; and navigation.php file with an includes tag.
  2. Filed additional pages under root/pages. Below is a snapshot of my current folders:
  • root
    • pages
    • assets
    • images
    • js
    • php

My issue now that I have nested additional pages (other than index.html) in the pages folder. When coding these files, the link/include files are causing issues, because of the relative/absolute file reference. Through some research I was able to use this php code which seems to work for the header, footer, and navigation menu:

<?php 
set_include_path( implode( PATH_SEPARATOR, array(
$_SERVER['DOCUMENT_ROOT'],
get_include_path()
) ) );

include 'root/assets/header.php';

?>

The issue I have now is the css link no longer works either:

 <link rel="stylesheet" href="css/style-services.css">

I have tried doing this with no luck:

<?php 
set_include_path( implode( PATH_SEPARATOR, array(
$_SERVER['DOCUMENT_ROOT'],
get_include_path()
) ) );

include 'root/css/style-services.css';

?>

How do I insure the referenced css also gets included when using a file structure and php include functions?

bkper087
  • 11
  • 3

1 Answers1

0

Don't include the CSS file, just echo it. Like:

<?php
//
// your other cods here
//
$style_services = file_get_contents ("root/css/style-services.css");
echo $style_services;
//
// your other cods here
//
?>
Ęstiv Əstiv
  • 170
  • 1
  • 8