You are not logged in.
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:
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
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
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 ‘<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 “<meta description=’$customMeta’ />”; } } </code></pre>Place <my_meta /> into the head of your page.
This should be a little faster, beauce there is only one db-query.
If you call <article /> there are some more and you don’t need to call conditional tags
Offline
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
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
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
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
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
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
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