Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Add description field to categories (or section)
How can I add description to every categories?
Offline
Re: Add description field to categories (or section)
wornout wrote:
How can I add description to every categories?
You can cheat like I do:
- Make a Form called
cat-descriptions
- Inside that form, put a seriers of these:
<txp:variable name="desc-catname-1">Description of category goes here</txp:variable>
<txp:variable name="desc-catname-2">Description of category goes here</txp:variable>
- …
- Make sure to include that form somewhere near the top of your Page flow, e.g. in your
<head>
section do<txp:output_form form="cat-descriptions" />
- Anywhere you want to output the description, e.g. in a category list, do this:
<txp:variable name='desc-<txp:category />' />
Hope that helps.
EDIT: you could replicate the functionality of Steps 1-3 using the adi_variables plugin: as long as you trusted your users to create the variable names correctly, it’ll work. And you can always wrap <txp:if_variable>
around the description when you output them, so you can fail gracefully if one’s mangled or missing.
Last edited by Bloke (2012-02-23 15:37:58)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Add description field to categories (or section)
Thanks Stef!
Just what I wanted!
Offline
#4 2012-02-23 18:36:44
- milosevic
- Member
- From: Madrid, Spain
- Registered: 2005-09-19
- Posts: 390
Re: Add description field to categories (or section)
Another way, specially if you want to store more info per category than a simple text:
1.) create a section called, for instance, “metacategories”. Don’t forget to hide this section for search, home page, menus, etc.
2.) Per category, create a new article in section “metacategories” Assigning it to category1 (or 2) —> the category you want to describe.
For retrieve a category meta information, use <txp:article_custom section=“metacategories” category=‘THE-CATEGORY YOU WANT’/>
This way you can use title, body, excerpt, dates, custom fields, images… for store multiple information per category.
For instance the article title can be the long version of the category name (cat title: Vegetables > long title: Our great and fresh vegetables)
then:
<txp:article_custom section=“metacategories” category=“vegetables”><txp:title/></txp:article_custom>
The same way with photos, long text, etc.
Last edited by milosevic (2012-02-23 18:41:00)
<txp:rocks/>
Offline
Re: Add description field to categories (or section)
[OT] To use hidden section(s) btw is a good standard method to realize structured content databases for all kind of data. Not sure if such a How-To is covered in the documentation somewhere. Would also make a TXPtip or an article for the new TXPmag :)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline