Skip to content

Instantly share code, notes, and snippets.

@aerouk
Created November 22, 2016 18:19
Show Gist options
  • Save aerouk/49573856fcb1da1774345647a3289a86 to your computer and use it in GitHub Desktop.
Save aerouk/49573856fcb1da1774345647a3289a86 to your computer and use it in GitHub Desktop.
<?php
/**
* Generates a path string for the page header with relevant breadcrumb links.
*
* @param $page string page value of page user is currently accessing (path/format/is/as/such)
* @return string breadcrumb string
*/
function getPathStr($page)
{
$path = explode('/', $page);
$pathStr = "";
for ($i = 0; $i < count($path) - 1; $i++) {
$thisPath = array_slice($path, 0, $i + 1);
$pathHpl = count($thisPath) > 1 ? implode('/', $thisPath) : $thisPath[0];
$pathStr .= linkify($path[$i], $pathHpl) . " / ";
}
$pathStr .= $path[count($path) - 1];
return $pathStr;
}
function linkify($input, $link)
{
return "<a href='/$link'>$input</a>";
}
@aerouk
Copy link
Author

aerouk commented Nov 22, 2016

This is how I utilised the function:

  • Pass current path (in this case mc/nether)
  • Print result into header with hyperlink CSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment