<?php
// This is a PLUGIN TEMPLATE.
// Copy this file to a new name like abc_myplugin.php. Edit the code, then
// run this file at the command line to produce a plugin for distribution:
// $ php abc_myplugin.php > abc_myplugin-0.1.txt
// Plugin name is optional. If unset, it will be extracted from the current
// file name. Uncomment and edit this line to override:
#$plugin['name'] = 'plugin_name';
$plugin['version'] = '0.2';
$plugin['author'] = 'Gerhard Lazu';
$plugin['author_uri'] = 'http://gerhardlazu.com/';
$plugin['description'] = 'SEO friendly title tags';
$plugin['type'] = 0; // 0 for regular plugin; 1 if it includes admin-side code
// 0 = Plugin help is in Textile format, no raw HTML allowed (default).
// 1 = Plugin help is in raw HTML. Not recommended.
$plugin['allow_html_help'] = 1;
if (!defined('txpinterface'))
@include_once('txp_plugin_template/zem_tpl.php');
if (0) {
?>
# --- BEGIN PLUGIN HELP ---
<style type="text/css" media="screen,projection">
<!--
#glz_plugin_help {
margin: 0 auto;
font-family: Verdana,"Lucida Grande",sans-serif;
padding: 15px;
background-color: #F7F7F7;
border: 1px dotted #EBEBEB;
width: 700px;
color: #333;
font-size: 12px;
line-height:15px;
}
#glz_plugin_help p, #glz_plugin_help ul, #glz_plugin_help ol, #glz_plugin_help dl {
font-size: 12px;
line-height: 15px;
margin-bottom: 15px;
}
#glz_plugin_help ul {
padding-left: 15px;
list-style: square;
}
#glz_plugin_help ol {
padding-left: 20px;
}
#glz_plugin_help a, #glz_plugin_help a.visited {
color: #FF7B00;
text-decoration: none;
padding-bottom: 1px;
border-bottom: 1px dotted #FF7B00;
}
#glz_plugin_help a:hover {
color: #FFF;
background-color: #FF7B00;
border-bottom: 1px dotted #FF7B00;
}
#glz_plugin_help h1 {
font-family: Georgia,Times,Serif;
font-size: 24px;
font-weight: normal;
text-decoration: none;
line-height: 30px;
margin-bottom: 15px;
color: #333;
letter-spacing: -1px;
}
#glz_plugin_help h2 {
font-family: Georgia,Times,Serif;
color: #FFF;
font-size: 18px;
font-weight: normal;
line-height: 30px;
margin-bottom: 15px;
background-color: #C1C4C3;
padding-left: 15px;
text-transform: uppercase;
}
#glz_plugin_help strong {
}
#glz_plugin_help code {
line-height: 16px;
font-style: italic;
font-family: Monaco,"Courier New", Courier, monospace;
font-size-adjust: none;
font-stretch: normal;
font-variant: normal;
font-weight: normal;
font-size: 12px;
color: #000;
}
#glz_plugin_help code.txp {
background-color: #FFF6A9;
font-family: Monaco,"Courier New", Courier, monospace;
line-height: 30px;
font-style: normal;
padding: 2px 0;
color: #000;
}
-->
</style>
<div id="glz_plugin_help">
<h1>glz_title, SEO friendly page titles</h1>
<h2>Requirements</h2>
<ul>
<li>minimum <strong>TXP 4</strong> (<a href="http://www.tetpattern.com/download" title="Latest Stable Textpattern Download">TXP 4.0.6</a> recommended)</li>
<li>without <a href="http://gerhardlazu.com/blog/51/glz_custom_fields-11-released">glz_custom_fields</a> you will need to write 2 of the functions I'm relying on...</li>
</ul>
<h2>Usage</h2>
<code class="txp"><txp:glz_title title_format="{page_title}. {site_slogan} - {sitename}" /></code>
<p>Put the above in the head of your page, preferably straight after <head> It formats the title according to the <b>title_format</b>. Default is: <b>Article title. Site slogan - Sitename</b></p>
<p>The interesting part is that this little plugin fetches the title of the article in a list that has one of the categories set to Section-Article. If under a section we have multiple articles, but one of them we want to use as master, all we have to do is assign it a Category of "Section-Article". Obviously, you need to create this category first.</p>
<p>If there is a 404 error, title will show <b>Sitename - error message.</b></p>
<h2>Improvements</h2>
<p>If you want to improve on this plugin, by all means, fork it and make it yours :). This plugin has been originally posted on <a href="http://github.com/gerhard/glz_title/tree/master" title="glz_title on Github">Github</a>. <a href="http://git.or.cz" title="Git - Fast Version Control System">Git</a> is a lovely little thing.</p>
</div>
# --- END PLUGIN HELP ---
<?php
}
# --- BEGIN PLUGIN CODE ---
// <?php
/**
glz_title plugin, FROM UK WITH LOVE
@author Gerhard Lazu
@version 0.2
@copyright Gerhard Lazu, 15 Apr, 2008
@package TXP 4.0.6 (2805)
*/
function glz_title($atts) {
global $is_article_list, $s, $sitename, $status, $txp_error_message, $site_slogan, $thisarticle, $siteurl;
extract(lAtts(array(
'title_format' => '{page_title}. {site_slogan} - {sitename}',
),$atts));
$s = ( ($s == "") || ($s == "default") ) ? "home" : $s;
// let's get our section title first, we might need it
$section_title = section(array('title' => "1"));
if ( $status == "404" )
// display just the sitename and the error message if we get an error
return "<title>$sitename - $txp_error_message</title>";
if ( $is_article_list ) {
// if this is a list, let's see if any of the articles are set as Section-Article
$section_article = safe_row("*", "textpattern", "section = '$s' AND (Category1 = 'Section-Article' OR Category2 = 'Section-Article' ) AND Status = '4'");
// only proceed if we really have a Section-Article
if ($section_article) {
// check if we have a custom field named "Page Title"
$title_field = glz_custom_number(glz_get_custom_set("Page Title"));
// look for the "Page Title" custom value within the article if the custom field has been set, if not just use the article Title to build the page title
// we are using both Page Title and Title for articles because we might want finer granularity.
// generally, we would use article Title for the heading, Page Title for the actual page title
$page_title = ( $title_field && !empty($section_article[$title_field]) ) ? $section_article[$title_field] : $section_article['Title'];
}
else
// if none of the aboe are met, just use the section title
$page_title = $section_title;
}
else
// the default will always be the article Title
$page_title = $thisarticle['title'];
// return our page title formatted as specified in 'title_format' attribute
$out = str_replace(
array("{page_title}", "{site_slogan}", "{sitename}"),
array($page_title, $site_slogan, $sitename),
$title_format
);
return "<title>$out</title>";
}
# --- END PLUGIN CODE ---
?>