At the moment my favorite tool for custom tailored web sites is ProcessWire.
If you never heard about it before, it is a very clever piece of PHP-based Content Management System/Framework with a very powerful but intuitive API which plays very nicely along with other applications. I have build (or was involved in) projects based on ProcessWire from small personal to large corporate and e-commerce sites, over the last two years and it has turned out to be a really great and flexible tool.
Here is a little snippet I just submitted to processwire-recipes.com since I use this on nearly every site to have the html page <title> Tag reflecting the rootline (the line of ancestor pages up to the root or home page)
function renderPageTitle($options=array()){ $defaults = array( 'glue' => ' « ', // ' » ' 'reverse' => true // false ); $opts = array_merge($defaults,$options); $page = wire('page'); $parents = $page->parents; $items = array(); foreach($parents as $parent) { $items[] = $parent->title; } $items[] = $page->title; if($opts['reverse']){ $items = array_reverse($items); } $out = implode($opts['glue'],$items); return $out; } |
In the template you can then use it like this:
$htmTitle = renderPageTitle(); ... <title>< ?php echo $htmlTitle; ?></title> ... |
There are two options you can set by giving an array as the only parameter to the function; "reverse" can either be true or false, and triggers if the current page is at the start or at the end of the rootline, "glue" is a string that will be used as a separator between the page titles.
Say you have this tree structure:
- Home
- - Articles
- - - Article A
The by default the returned string for the title tag would look like this: Article A « Articles « Home
.
If you want to reverse the order,
renderPageTitle(array('reverse'=>false)); |
will result in this: Home « Articles « Article A
.
Since now the "glue"'s arrow is the wrong way,
renderPageTitle(array('reverse'=>false,'glue'=>' » ')); |
will change it to: Home » Articles » Article A
.
Of course you can use any character or combination of characters you like:
renderPageTitle(array('glue'=>' ::: ')); |
results in: Article A ::: Articles ::: Home
3 Reaktionen zu “Rootline HTML page title for ProcessWire”
Heute war irgendwie, obwohl völlig anders geplant, ein produktiver Coding-Sonntag. Ich bin über ein interessantes WordPressproblem gestolpert, habe ein Codesnipped für ProcessWire veröffentlicht und ein Proof-of-Concept für ein laufendes (Arbeits)Projekt fertigbekommen.
Yay.
Allerdings blieb da kaum noch mentale Luft für den Daily Sketch, der deshalb heute sehr mager ausfällt und auch irgendwas mit Code/Zeichen zu tun hat.
<°)
<(( ))>
= =
Möglicherweise ist das alles Prokastination, weil ich eigentlich meinen Vortrag für den Webkongress Erlangen ins Reine schreiben müsste. Das Thema wird aber immer größer, je mehr ich da recherchiere, und das macht mir ehrlich gesagt gerade ein wenig Sorgen. :-)
Kommentare sind geschlossen.