Well of Stars

Tips and Troubleshooting: Skinning pages in subfolders?

If the content pages of your site are not all in your main directory, but instead are organised in subfolders, you will need to make a few modifications for the skins to work correctly on all your pages. There are two possible ways of doing this.

Fix One

The Base URL

In each header.php, within the <head> section, you need to add a base url for the site. This should be in the format,

<base href="http://www.yourdomain.com/">

or if your site is hosted on a subdomain:

<base href="http://subdomain.yourhost.com/">

This means that all the internal links within your site - to images, css file, other pages (i.e. all your links that don't include a 'http://' ) will be relative to this url. Once you have added this, the links to css and other layout files within your header.php will be correct for all your pages. However, depending on how your files are organised, you may need to update some internal links within your content pages. For example, you might have a subfolder 'gallery' containing the .php pages for your gallery and your gallery images. Whereas before your image links would have been <img src="picture.jpg">, you will now need to include the gallery folder in the link: <img src="gallery/picture.jpg">.

Links to change the skins

You will also need to include some php code for the links to your skins, if you want to be able to change skins and remain on the same page. The basic link <a href "?newskin=1"> will still work, but it will always take you back to your index page. To fix this, include the following code:

<?php
$url=$_SERVER['REQUEST_URI'];
if (strpos($url,"?")>0) $url=substr($url,0,strpos($url,"?"));

echo "<a href=\"$url?newskin=1\">Skin 1</a>
<a href=\"$url?newskin=2\">Skin 2</a>";
?>

Include the links for however many skins you have. If you are using images to link, make sure that any quote mark (") in the code for the image is preceeded by a slash (\) (e.g. <a href=\"$url?newskin=1\"><img src=\"skin1.gif\"></a>). Make sure that the closing tag for the link to your last skin is followed by "; (this closes the 'echo' request).

Fix Two


Alternatively, you could include the base url for your site (http://www.yourdomain.com/) in any internal links in your header and footer.php files. This means the link for your css file etc, any images, and all your navigation links in these files should be updated.

Subfolders and php includes without skins


If you're using regular php includes, as described in Section 3, you will need to include the base href or modify the internal links in your header and footer.php files as above. You will also need to change your php code to include the full file path for your header and footer php files. These will then look something like:

<?php
@ require_once ($_SERVER['DOCUMENT_ROOT']."/header.php");
?>

(and similarly for footer). If this doesn't work, see the section on 'checking the file path' for how to find the correct path.

On to tips and troublshooting: skins and subdomains
Back to contents