Created
January 10, 2011 22:15
-
-
Save kcrwfrd/773579 to your computer and use it in GitHub Desktop.
Automatically define page ID & class based on file name and folder structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Default Page Title | |
$page_title = "Default Page"; | |
// Set relative URL | |
$url = '/'; | |
// Set $page_id & $page_class | |
$page_id = $page_class = ''; | |
$urlExplode = explode("/", $url); | |
$pathName = $_SERVER['SCRIPT_NAME']; | |
$pathExplode = explode("/", $pathName); | |
$page_id = explode(".", end($pathExplode)); | |
$page_id = $page_id[0]; | |
$page_class = $page_id; | |
if (count($pathExplode) == count($urlExplode) && $page_id == "index") { | |
$page_id = "home"; | |
$page_class = $page_id; | |
} elseif (count($pathExplode) > count($urlExplode) && $page_id == "index") { | |
$sectionNo = (count($pathExplode) - 2); | |
$page_id = $pathExplode[$sectionNo]; | |
$page_class = $page_id; | |
} elseif (count($pathExplode) > count($urlExplode)) { | |
$sectionNo = (count($pathExplode) - 2); | |
$page_class = $pathExplode[$sectionNo]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment