PHP 'include' a relative file?

Started by
9 comments, last by Servant of the Lord 11 years, 8 months ago
Thanks for all the help guys, it's working well now.

For anyone else banging their head against this in the future, apparently the "<?php header("Content-type: text/css; charset: UTF-8"); ?>" must be the very first line in the file, even before comments and empty lines (PHP: header).

I haven't gotten the file to be a .css or .php-css file yet, I'll probably try some more at that tomorrow, but for now it's just a .php.

Another thing of note is that because I'm including it as:
<link rel="stylesheet" type="text/css" media="all" href="path/to/my/style.php" />

...and it's being linked, and not PHP include()'d, all my PHP functions and variables aren't included, so I have to within the 'style.php' file call:
<?php include('functions.php'); ?>
...but my functions.php depends on the WordPress function 'get_stylesheet_directory()' for resolving paths properly, and because the 'style.php' file is being linked, not included, all the WordPress functions are no longer available, so I had to definie my own 'get_stylesheet_directory()' if WordPress' isn't present:
if (!function_exists('get_stylesheet_directory'))
{
function get_stylesheet_directory()
{
return dirname(__FILE__);
}
}


I really appreciate all the help, gentlemen. It's working perfectly now and it would've taken me probably ten days or more of head-banging instead of just three to figure it all out, and I probably would've given up before then.

This topic is closed to new replies.

Advertisement