Textpattern Forum

You are not logged in. Register | Login | Help

#1 2006-06-01 14:12:08

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

[howto] Article dependent meta description in page header

I had a feature request and found the solution myself by research in the forum. Here is my solution:

Original feature request for a meta description plug-in

I am looking for a plug-in which only generates a meta-description tag. Somehow a meta-description generator with the following features is not available.

Features:

  1. Some pre-defined leading text
  2. if article – The standard TXP keywords for that article (optional: custom field)
  3. if article list – some pre-defined keywords
  4. if search result – some pre-defined keywords
  5. Some pre-defined trailing text
  6. An option to cut the meta-description tag to a maximum length

The workaround solution. Not covering all points from the feature request but already satisfying (myself).

Create form ‘meta_articletitle’. Content:

<meta name="description" content="Some pre-defined leading text: <txp:title /> - <txp:keywords /> - Some pre-defined trailing text" />

Create form ‘meta_description’. Content:

<txp:if_individual_article>
<txp:article form="meta_articletitle" />
</txp:if_individual_article>
<txp:if_article_list>
<meta name="description" content="Some pre-defined leading text: <txp:sitename /> - Some pre-defined trailing text" />
</txp:if_article_list>

Call form ‘meta_description’ in page header:

<txp:output_form form="meta_description" />

Of course you can play around with the used tags in the forms ‘meta_articletitle’ and in ‘meta_description’ as you like. In form ‘meta_description’ you must make sure to only use tags which are allowed in the header context!

Edit: Fast add-on tip for lists (beside all the if/else conditions you may want to add): Add page number <txp:page_url type="pg" /> to cover multiple page lists.

You can see the results on my German page sankt-georg.info.

Coments and refinements welcome!

Last edited by merz1 (2010-10-28 12:26:20)


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

Offline

#2 2006-06-01 21:44:20

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,397
Website

Re: [howto] Article dependent meta description in page header

I moved this to How-tos and Examples. There is btw a similar post about customizing page titles.


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

Offline

#3 2006-06-01 22:39:21

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: [howto] Article dependent meta description in page header

Propaply a little plugin will do this job better.

I didn’t test it, but something like should work

<pre><code> function my_meta($atts,$thing){ global $pretext; if(emty($pretext[‘id’])){ //if empty, we handle a list return ‘&lt;meta description=“standard text” /> ‘; } else{ //we have to fetch the custom-field, //because $thisarticle is not defined $customMeta = fetch(‘custom_x’,‘textpattern’,‘ID’,$pretext[‘id’};); return “&lt;meta description=’$customMeta’ />”; } } </code></pre>

Place &lt;my_meta /> into the head of your page.

This should be a little faster, beauce there is only one db-query.
If you call &lt;article /> there are some more and you don’t need to call conditional tags

Offline

#4 2006-06-02 17:17:30

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,397
Website

Re: [howto] Article dependent meta description in page header

I would like to try this, Bastian, but does it mean that I have to enter my “standard text” in the plugin code? And replace ‘x’ in custom_x with the number of the customfield I suppose? Or should that be the name of the custom field?


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

Offline

#5 2006-06-02 17:57:17

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: [howto] Article dependent meta description in page header

you could include a $default attribute to the code of the plugin so people can set that without altering the plugin, same with setting the custom field to query.

Offline

#6 2006-06-02 18:42:30

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: [howto] Article dependent meta description in page header

If someone wants such a plugin, let me know.
I use a plugin like this to deliver JS and CSS by section or atricle. So i could change thatone.

Offline

#7 2006-06-02 18:50:25

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: [howto] Article dependent meta description in page header

Bastian wrote:

If someone wants such a plugin, let me know.
I use a plugin like this to deliver JS and CSS by section or atricle. So i could change thatone.

This sounds very interesting indeed. I am looking for a solution to dynamically switch css for different sections. Would such a plugin be difficult to write?

Offline

#8 2006-06-02 18:52:10

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,397
Website

Re: [howto] Article dependent meta description in page header

You don’t need a plugin for that?! What about setting it in Presentation > sections? Or do I completely misunderstand you?


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

Offline

#9 2006-06-02 18:56:41

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: [howto] Article dependent meta description in page header

I am looking for a solution to dynamically switch css for different sections. Would such a plugin be difficult to write?

Switching by sections isn’t difficult, because it is build-in in txp :)
You can define a css for each section

Adding CSS or JS for each article is a little more difficult.
But not much.

I have a custom-field wich contains CSS or JS files, if a article needs them.

For example this one contains CSS and JS fiels wich are not included by the parent section.

A plugin reads only the custom-field (like mentioned above) and includes the needed files into the head.

Offline

#10 2006-06-02 19:05:48

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: [howto] Article dependent meta description in page header

Yah..I misworded my post. I would like to assign css to sections and certain articles as well.

I just discovered the joy of custom fields today…never occured to me to use them to assign css on the fly. Probably because I dont have this plugin of yours ;)

Offline

Board footer

Powered by FluxBB