Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-01 19:32:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Insert the article category matching a specified parent as variable

Hi!

I’m working on a site that has a section in which articles are listed on three separate category-based landing pages, but the individual articles should not be accessed at their own URLs. I’m trying to edit my search_results article form to accommodate this scheme, but in order to do so I need to insert the article categories into variables based on their parents.

Each article in the section is tagged with one or two categories: one is a child of the ‘topics’ category, the other is a child of the ‘branches’ category.

Here’s what I have so far:

<txp:variable name="topic"><txp:if_category name='<txp:category_list break="," exclude="topics" parent="topics"/>'>
<!--
	TODO insert category1 or category2 from this article where the parent is 'topics'
-->
</txp:if_category></txp:variable>
<txp:variable name="branch"><txp:if_category name='<txp:category_list break="," exclude="branches" parent="branches"/>'>
<!--
	TODO insert category1 or category2 from this article where the parent is 'branches'
-->
</txp:if_category></txp:variable>

Once I get the correct categories set into the “topic” and “branch” variables, using if_variable logic to assign the correct permalinks will be a snap. But I don’t know how to insert the category name that matches the specified parent— category1 and category2 return the assigned category without respect to the parent.

I may be overlooking a totally obvious solution. Any suggestions would be immensely appreciated!

Offline

#2 2011-06-01 21:16:00

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Insert the article category matching a specified parent as variable

Just to begin with anything: would smd_parent help?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2011-06-06 19:49:08

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: Insert the article category matching a specified parent as variable

Thanks, Uli. I’ve been using smd_parent on this site, but it didn’t seem to fit what I was trying to do. I figured it out today— here’s the code that worked:

<txp:variable name="topic"><txp:if_article_category number="1" name='<txp:category_list break="," exclude="topics" parent="topics"><txp:category/></txp:category_list>'><txp:category1/><txp:else/><txp:if_article_category number="2" name='<txp:category_list break="," exclude="topics" parent="topics"><txp:category/></txp:category_list>'><txp:category2/></txp:if_article_category></txp:if_article_category></txp:variable>
<txp:variable name="branch"><txp:if_article_category number="1" name='<txp:category_list break="," exclude="branches" parent="branches"><txp:category/></txp:category_list>'><txp:category1/><txp:else/><txp:if_article_category number="2" name='<txp:category_list break="," exclude="branches" parent="branches"><txp:category/></txp:category_list>'><txp:category2/></txp:if_article_category></txp:if_article_category></txp:variable>

Offline

Board footer

Powered by FluxBB