Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-20 18:05:49

strawberryfusion
Member
Registered: 2005-07-24
Posts: 20

Using conditionals

Hi,

I am having a hard time trying to do the following – I have looked through the forums and none of the solutions I have found have worked. Maybe I have missed a post in my search?…

I have a section called ‘beds’ in there I have several articles, each with a different category label. I then have several other sections… ‘repose’, ‘pillow’, ‘pocket’ and so on… Each of these sections has it’s own set of articles.

What I want to do is when an article is clicked in the beds section and if it has information about ‘pillow’, I want only the artciles from the ‘pillow’ section to be displayed and if I go to an article related to ‘pocket’ in the ‘bed’ section, then I want only articles from the ‘pocket’ section to be displayed.

I thought this would be straight forward to do using conditional and section/category labels. What I end up getting is articles from all the sections displaying in any of the articles from the bed section?

I’m using something like:

<code><txp:if_article_category name=“pocket” />
<ul id=“subnav”><txp:article_custom form=“subnav” section=“pocket” sortby=“custom_1” sortdir=“asc” /></ul>
</txp:if_article_category>

<txp:if_article_category name=“pillow” />
<ul id=“subnav”><txp:article_custom form=“subnav” section=“pillow” sortby=“custom_1” sortdir=“asc” /></ul>
</txp:if_article_category></code>

I have tried using variations of this but no luck there – any idea where I’m going wrong?

Many thanks
rajiv

Last edited by strawberryfusion (2006-01-20 18:06:45)

Offline

#2 2006-01-20 18:13:35

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Using conditionals

Where are you placing the code? The “if_article_category” tag can only be used in the article’s form template.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2006-01-20 18:54:35

strawberryfusion
Member
Registered: 2005-07-24
Posts: 20

Re: Using conditionals

Hi Stuart,

I orginally placed the code in the template page, then I put it in a form template and called it from the page template using:

<code><txp:output_form form=“myform” /></code>

That did not work either – am I doing something wrong?

Many thanks
rajiv

Last edited by strawberryfusion (2006-01-20 18:54:57)

Offline

#4 2006-01-20 19:03:32

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Using conditionals

No. What I meant was that the code has to be inside the form you use for your articles. That’s the only way it can connect with an article’s category.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#5 2006-01-20 19:17:11

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Using conditionals

If you change the tag to <txp:if_category> it’ll probably work.

txp:if_category is for use in a page template, it says: if we are on a category page
txp:if_article_category must be used in an article form, it says: if this article’s category is …

Offline

#6 2006-01-21 17:24:10

strawberryfusion
Member
Registered: 2005-07-24
Posts: 20

Re: Using conditionals

Hi Stuart/Els,

Tried your suggestions – still no luck. I’m not sure what I am doing wrong but I must be if you are saying it should work.

I looked at these posts:

http://forum.textpattern.com/viewtopic.php?id=12793

http://forum.textpattern.com/viewtopic.php?id=14106

As they seem similar to what I need to do but I’m not having luck with them either. Could there be an issue with my installation of Textpattern?

Many thanks
rajiv

Offline

#7 2006-01-21 18:17:26

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Using conditionals

Hi Rajiv,

Reading your first post again, some questions arise ;)

In your code, you are using section and category for the same things, like ‘pillow’. Can you please tell exactly what are your sections and what are your categories?

Second, am I right in understanding that, when a single article is displayed, you want to show an additional list of articles in the same category as the main article?

Offline

#8 2006-01-21 19:07:03

strawberryfusion
Member
Registered: 2005-07-24
Posts: 20

Re: Using conditionals

Hi Els,

Yes I did at first and then thought there may be an issue with that, so I changed the name of the categories to be different to the section names. Now I am using:

For sections:

Pillows, Pocket, Repose

For category:

pillow-cat, pocket-cat, repose-cat

For your second question – yes that is what I want to do.

Many thanks
rajiv

Offline

#9 2006-01-21 20:08:53

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Using conditionals

What happened to your section ‘beds’? What I originally understood was that articles in section ‘beds’ can have category ‘pillows’, ‘pocket’ or ‘repose’.

So I’m still not sure I’m getting it right. Articles in section ‘pillows’ can have one (or two?) of the categories ‘pillow-cat’, ‘pocket-cat’ and ‘repose-cat’? Or does an article in section ‘pillows’ always have category ‘pillow-cat’? (which wouldn’t add much to the functionality in my opinion).

Just more questions for you, sorry about that ;)

I don’t think it’s a problem having categories with the same names as sections, technically spoken, it just might save you some confusion if you can avoid that.

Offline

#10 2006-01-21 20:29:47

strawberryfusion
Member
Registered: 2005-07-24
Posts: 20

Re: Using conditionals

Hi Els,

Sorry – yes the section ‘beds’ is there which has various articles with categories assigned to them from ‘pillow-cat’, ‘pocket-cat’ or ‘repose-cat’. No for section ‘pillows’ I was not using any category but relying on sections:

<code><txp:if_article_category name=“pillow-cat” />
<ul id=“subnav”><txp:article_custom form=“subnav” section=“pillows” sortby=“custom_1” sortdir=“asc” /></ul>
</txp:if_article_category></code>

So what is supposed to happen is if you go to the sections called ‘beds’ and click on one of the articles – for example an article that has been assigned the category ‘pillow-cat’, you would then see a list of articles from the section ‘pillows’. This would be the same for the other categories, if you clicked on an article in sections ‘beds’ that has been assigned with a category ‘pocket-cat’, you would see a list of articles from the section ‘pocket’ and so on…

No worries about the questions – better to be clear! I wish my brain was ;-)

Many thanks
rajiv

Offline

#11 2006-01-21 21:25:39

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Using conditionals

Ah. Now I’m confused. Anyway if you click on an article’s title it will take you to an individual_article view for that article where the comments and comment entry form will also appear if comments are allowed. If you want a category listing then you should ensure that you use the category1 (and) category2 tags in your article’s form template and that it/they is/are linked like so <code><txp:category1 link=1 title=1 /></code>, but then you have the problem of the resulting listing trying to use your front-page by default so have a look at this bit of magic to make it use your current page.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#12 2006-01-21 21:52:31

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Using conditionals

Hi Rajiv,

Finally I get the picture ;) It’s not an obvious thing that you are trying to do, and can be a bit of a problem, for the reason Stuart already pointed out earlier: the <txp:if_article_category> tag can only be used inside an article form, because if you use it elsewhere, there is no way the tag can know which article we are talking about.

There is a way to do it, but that may cause problems with positioning, if for instance you’d like to have the article list in your sidebar.
If you put your code inside your single article form, it will work. And if you’re good with CSS, you might be able to think of a way to position it away from the main article.

Last edited by doggiez (2006-01-21 21:54:23)

Offline

Board footer

Powered by FluxBB