Skip to content

Instantly share code, notes, and snippets.

@kcrwfrd
Created January 10, 2011 22:15
Show Gist options
  • Save kcrwfrd/773579 to your computer and use it in GitHub Desktop.
Save kcrwfrd/773579 to your computer and use it in GitHub Desktop.
Automatically define page ID & class based on file name and folder structure
<?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