Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-11-19 03:12:30

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

[feedback] [Suggestion] Improve page_title tag

Hi developers,

I suggest an update on page_title for better SEO

<txp:page_title />

Article List

Your site name

Articles by Category

Your site name : Category title

Search Results page

Your site name : Search results: Search term

Single Article page

Your site name : Article name

Comments display

Comments on: Article name

This should allow user to change the display order, and currently all sites such as techcrunch.com…. they display the title as below

Article List

Your site name

Articles by Category

Category title : Your site name

Search Results page

Search term : Search results : Your site name

Single Article page

Article name : Your site name

Comments display

Article name : Comments on

Tks

Last edited by HAC (2011-11-19 04:30:45)

Offline

#2 2011-11-19 04:31:05

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

Re: [feedback] [Suggestion] Improve page_title tag

I’ve just made a stupid modification to make for my site ^^ but it works

function page_title($atts) { global $parentid, $thisarticle, $id, $q, $c, $context, $s, $pg, $sitename;

extract(lAtts(array( ‘separator’ => ‘ | ‘, ), $atts));

$out = ‘’;

if ($parentid) { $parent_id = (int) $parent_id; $out .= gTxt(‘comments_on’).’ ‘.escape_title(safe_field(‘Title’, ‘textpattern’, “ID = $parentid”)); } elseif ($thisarticle[‘title’]) { $out .= escape_title($thisarticle[‘title’]); } elseif ($q) { $out .= gTxt(‘search_results’).htmlspecialchars($separator.$q); } elseif ($c) { $out .= htmlspecialchars(fetch_category_title($c, $context)); } elseif ($s and $s != ‘default’) { $out .= htmlspecialchars(fetch_section_title($s)); } elseif ($pg) { $out .= gTxt(‘page’).’ ‘.$pg; } else { $out = htmlspecialchars($sitename); }

if ($out != htmlspecialchars($sitename)) { $out .= htmlspecialchars($separator.$sitename); }

return $out; }

Offline

#3 2011-11-20 12:42:49

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: [feedback] [Suggestion] Improve page_title tag

Welcome to the TXP forum!

I suggest not to make modifications to TXP core files.

Instead use txp:output_form and 1-n forms to define the header meta tag outputs you want.
Normally those forms will be called in your page header or in your header form.
Use form names starting with “meta_”.
Use TXP core standard txp:if_ tags inside those forms to achieve the exact content you want.

Example if/else skeleton in form meta_description:

<txp:if_individual_article>
<meta name="description" content="<txp:title no_widow="0" /> - <txp:keywords /> © trailing info" />
</txp:if_individual_article>

<txp:hide>You can nest and fill the following if/else conditions to your liking:</txp:hide>

<txp:if_article_list>
<txp:if_search>
<txp:else />
<txp:if_section>
<txp:else />
<txp:if_category>
<txp:else />
<txp:hide>(...)</txp:hide>
</txp:if_category>
</txp:if_section>
</txp:if_search>
</txp:if_article_list>

A trap to take care of: Some txp:tags don’t show up in page context.
Workaround: If you see no output call a second form.

PS: To show code here in the forum use textile bc., <code>@…@</code> or bc...

Edit: Added the <txp:else /> to show more basic logic :)

Last edited by merz1 (2011-11-20 12:48:42)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

Board footer

Powered by FluxBB