Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-08-24 18:51:56

yotiao
Member
From: UK
Registered: 2009-10-27
Posts: 28
Website

best practices with unlimited categories and two types of content?

Hello,

I have a site with two types of content: short posts and long articles (think Daring Fireball). I have set up specific forms for each of them, and display both on the front page using their major category:

<txp:article>
<txp:if_article_category name=“short”>
<txp:output_form form=“default” />
<txp:else />
<txp:output_form form=“long” /><hr />
</txp:if_article_category>
</txp:article>

Because I also want to have a possibility of assigning each post into several categories (apart from the category-used-to-display), and I want to have an archive page with these categories, I have installed unlimited categories plugin – and run into a small mess.

It all works fine, but for each post I have to select the major category in the drop down menu on the left AND select whatever categories I want extra from the unlimited categories menu below. If I only do the second one, my posts would be not categorized correctly by the code above (it does not see the ‘unlimited’ categories). If I only do first, I can only have one extra category. As it is now, it is ugly, and I want to improve it.

I would be very grateful if you could advise me on the best practices here and a better solution (=to have multiple categories for each post AND a way of displaying two types of content, each with its own form, on a front page).

cheers
yot

Offline

#2 2011-08-24 19:29:33

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: best practices with unlimited categories and two types of content?

One way of going about this is to use excerpt and body for the short and long articles, for example:

  • short article: has just an excerpt and no content in the body
  • long article: has body (and perhaps an excerpt too for things like the rss feed)

You can then use code like this to display either the long or the short article (the comments are just by way of explanation):

<!-- put the content of the body in a variable -->
<txp:variable name="is_body"><txp:body /></txp:variable>

<!-- test if the variable is empty or not -->
<txp:if_variable name="is_body" value="">
	<!-- is_body is empty = show short article -->
	    <txp:excerpt />
<txp:else />
	<!-- is_body contains something = show long article -->
	    <txp:body />
</txp:if_variable>

This frees you up to use the categories for what they are really meant for.

Note: you can also switch the roles of excerpt and body and use txp:if_excerpt to detect if there is an excerpt. There isn’t a txp:if_body tag, hence the above code.

Note 2: You can use the plugin bot_write_tab_customize to change the order of the excerpt and body fields in the write pane, which might fit well with this scenario. There’s no actual need to, but you immediately see on the write pane when an article is long and when it is short.

Last edited by jakob (2011-08-24 19:30:49)


TXP Builders – finely-crafted code, design and txp

Offline

#3 2011-08-26 11:16:01

yotiao
Member
From: UK
Registered: 2009-10-27
Posts: 28
Website

Re: best practices with unlimited categories and two types of content?

Hi,

thanks a million for the answer! I will try that – I would have to make sure that I can fix my form for the ‘short’ articles to accomodate excerpts.

I have an additional question though – would the solution you propose be useful if I some day decide that my short and long texts should be in the separate sections? Or at least if I wanted to be able to display only short or only long texts? Would it be possible in this case (with the body and excerpts used as a way to display two types of content)?

Thanks again,
yot

Offline

#4 2011-08-26 22:45:32

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: best practices with unlimited categories and two types of content?

You could use custom fields, too. Just have one called “is_long” (yes | no, default no) and you won’t have to waste categories.

I would personally try something like that before using excerpt vs. body, just to create an explicit workflow. But there’s not a gigantic difference.

Offline

#5 2011-08-29 08:17:40

yotiao
Member
From: UK
Registered: 2009-10-27
Posts: 28
Website

Re: best practices with unlimited categories and two types of content?

Whoa, this is cool. I have just tried to use the trick with custom fields and it worked beautifully. I had to do some manual work, because there is no way to set a default value to a custom field (I found a paid plugin for that, but I am not as advanced a blogger yet), but since I only have a few long articles so far, the default for the short text is an empty custom field (via a conditional), and I just put “yes” in my “is_long” custom field for each of the long articles. It works!

That was easy ;-)

Thanks!
yot

Offline

#6 2011-08-29 09:45:51

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: best practices with unlimited categories and two types of content?

yotiao schrieb:

I found a paid plugin for that, but I am not as advanced a blogger yet

Buy it – you won’t regret it :-) With glz_custom_field you will get checkboxes, radio buttons and dropdowns as custom fields with default values and much more. Couldn’t live without.

Offline

#7 2011-08-29 09:50:16

yotiao
Member
From: UK
Registered: 2009-10-27
Posts: 28
Website

Re: best practices with unlimited categories and two types of content?

phuture303 wrote:

Buy it – you won’t regret it :-)

Yeah, I know. I have nothing against paying for stuff I need, but as of now my needs are very simple, and I still don’t know if this blogging thing is my thing ;-)

cheers
yot

Offline

Board footer

Powered by FluxBB