Revision [1141]
This is an old revision of SmartTitle made by JsnX on 2004-09-08 02:49:25.
How to get smarter titles
By default, page titles in Wikka correspond to their WikiName.
Although this is consistent with Wiki philosophy, in some cases having a dumb WikiName as a title is pretty limiting:
- WikiNames make VeryLongTitlesQuiteDifficultToUnderstand;
- They are not an optimal solution for visibility in search engines;
- They cannot contain accents or other special characters;
Even though the AddSpace option might partially help, here's a quick and dirty way I figured out to produce smarter titles (you can see a working version of this action here).
This action adds to the title the highest-level header available in the page (in this case =====How to get smarter titles===== ). If no such header is found, then the standard WikiName is displayed.
First save the following code as actions/maketitle.php
<?php
$pagecontent = $this->page["body"];
for ($i = 2; $i <= 5; $i++) {
if (ereg( "(=){".$i."}(.*)(=){".$i."}\s+", $pagecontent, $title)) {
$title = str_replace("\"\"", "", $title[2]);
}
}
if ($title) echo $title;
else echo $this->AddSpaces($this->GetPageTag());
?>
$pagecontent = $this->page["body"];
for ($i = 2; $i <= 5; $i++) {
if (ereg( "(=){".$i."}(.*)(=){".$i."}\s+", $pagecontent, $title)) {
$title = str_replace("\"\"", "", $title[2]);
}
}
if ($title) echo $title;
else echo $this->AddSpaces($this->GetPageTag());
?>
Then make the following change in actions/header.php
old:
<title><?php echo $this->AddSpaces($this->GetWakkaName())." : ".$this->AddSpaces($this->GetPageTag()); ?></title>
new:
<title><?php echo $this->AddSpaces($this->GetWakkaName())." : ".$this->Action("maketitle"); ?></title>
Comments and improvements are welcome
-- DarTar
The original code above from DarTar didn't give the expected results. It was grabbing EVERYTHING between the first set of ===== and the last set. And even the revised fix code seemed to do the same thing. For example on this page, here's what it would return:
<title>Wikka : How to get smarter titles=====
By default, page titles in Wikka correspond to their WikiName.
Although this is consistent with Wiki philosophy, in some cases having a dumb WikiName as a title is pretty limiting:
- They are not an optimal solution for visibility in search engines;
- They cannot contain accents or other special characters;
Even though the AddSpace option might partially help, here's a quick and dirty way I figured out to produce smarter titles (you can see a working version of this action here).
This action adds to the title the highest-level header available in the page (in this case =====How to get smarter titles</title>
With DreckFehler's modification it wouldn't seem to work at all. It just kept showing the normal wikiword page title.
So I made my own modification to the regular expression and it seems to be working, but I'm sure there's room for improvement, and I'd be happy to get feedback.
Here's what I'm using:
function PageTitle() { $pagecontent = $this->page["body"]; for ($i = 2; $i <= 5; $i++) { if (ereg( "(=){".$i."}([A-Za-z0-9 ]*)(=){".$i."}", $pagecontent, $title)) { $title = str_replace("\"\"", "", $title[2]); } } if ($title) return $title; else return $this->GetPageTag(); }