Textpattern ob1_title Modded
I’ve been using the ob1_title Textpattern plugin on this site but was in need of a small addition. I wanted to display the category of a given article in the title, rather than only displaying the category if the user is browsing the page by category. This is because on a single article view my categories would never show. You can see the result in the title of this very page.
The mod to the plugin supports the changecase option on the category names if the casewhere option is set to “all”. If not, your category names will appear as they do normally.
In order to get the same effect, there a couple mods that need to be made to the plugin file. I am working with the newest version (1.4) so if you don’t have that, get it first or this won’t work. I am also using “article” ordering. If you use “site” ordering, just make the changes as noted below and you should have no trouble seeing what needs to be added. And away we go…
First replace line 84 which reads:
$strTitle = fetch('Title','textpattern','ID',$fetchID);
With the following:
$rs = safe_row("Title,Category1,Category2","textpattern","ID='$fetchID'");
if ($rs) {
$strTitle = $rs["Title"];
$cat1= $rs["Category1"];
$cat2= $rs["Category2"];
}
Then, after the new line 98 where $pageTitle is set, add the following:
$cat1 = ( $cat1 && $casewhere "all" )
? ob1_changecase(
array(
"case"=>$changecase,
"casereplace"=>$casereplace,
),
$cat1
)
: $cat1 ;
$cat2 = ( $cat2 && $casewhere “all” )
? ob1_changecase(
array(
“case”=>$changecase,
“casereplace”=>$casereplace,
),
$cat2
)
: $cat2 ;
Finally, after the new line 139 which reads:
$toReturn = ($pageTitle) ? $pageTitle : "";
Add the following:
$toReturn .= ($cat1) ? $separator.$cat1 : '' ;
$toReturn .= ($cat2) ? $separator.$cat2 : '' ;
I use the plugin like so on my site to achieve the desired effect:
<txp:ob1_title order="article" separator=" :: " />
And Voila! When viewing an article you’ll now see Category1 and Category2 names showing up in your title if they are set.
Comments
23. November 2004
Nice mod! Since I am currently working on version two I will implement this in it when I get the chance. I am thinking of naming the attribute categoryonsingle.
Add a comment
You may use textile in your comment. Gravatars are enabled. Your email will not be displayed and will remain private. I reserve the right to edit or delete comments.
