Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-02-23 15:07:05

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Add description field to categories (or section)

How can I add description to every categories?

Offline

#2 2012-02-23 15:30:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Add description field to categories (or section)

wornout wrote:

How can I add description to every categories?

You can cheat like I do:

  1. Make a Form called cat-descriptions
  2. Inside that form, put a seriers of these:
    1. <txp:variable name="desc-catname-1">Description of category goes here</txp:variable>
    2. <txp:variable name="desc-catname-2">Description of category goes here</txp:variable>
  3. 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" />
  4. 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

Offline

#3 2012-02-23 15:46:09

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

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

#5 2012-02-25 12:15:28

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

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

Board footer

Powered by FluxBB