public
Description: This is a Textpattern plugin for SEO friendly titles.
Homepage: http://gerhardlazu.com
Clone URL: git://github.com/gerhard/glz_title.git
Search Repo:
glz_title / glz_title.php
100644 196 lines (168 sloc) 6.946 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?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">&lt;txp:glz_title title_format="{page_title}. {site_slogan} - {sitename}" /&gt;</code>
<p>Put the above in the head of your page, preferably straight after &lt;head&gt; 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 ---
 
?>