Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-11 12:11:19

sipke
Member
From: In a Galaxy far far away...
Registered: 2004-06-15
Posts: 16
Website

Some problems with conditional tags in 4.0.8

Hey guys, I would appreciate some inputs for the following problem.

I use forms and sticky/hidden articles for meta tag generation for my websites (title, keyword, description) and I used to use the following code:

<txp:if_section name=”“>
<txp:article_custom section=“homepage” status=“sticky” form=“meta_dynamic” />
<txp:else />
<txp:if_category>
<txp:article form=“meta_dynamic” status=“hidden” />
</txp:if_category>
<txp:if_individual_article>
<txp:article form=“meta_dynamic” />
<txp:else />
<txp:article status=“sticky” form=“meta_dynamic” />
</txp:if_individual_article>
</txp:if_section>

So I use a sticky article for the section pages and hidden articles for the category pages (the categories are linked to the section – mysite.com/section/?c=category).

My meta_dynamic form (article type):

<title><txp:title />: <txp:section title=“1” /> – <txp:site_name /></title>
<meta name=“description” content=”<txp:custom_field name=“meta_desc” />” />
<meta name=“keywords” content=”<txp:keywords />” />

I’m getting super meta tags for every pages but the category pages. For the category pages TXP puts out all the meta data for the articles belonging to the given category, so I can see all of them in the source.

I am using this method for several other websites, though they are not updated yet from version 4.0.6, I wanted to test first if everything works perfectly.

I have checked the generated page’s source with tag tracer and the conditionals are working as intended, just on the category pages I see the SQL queries articles with status=4 (it is the Live status) instead of status=2 (hidden).

I’m sure I’m missing something that changed in 4.0.8 but so far I couldn’t find out what :)

Anyone can help me please? Many thanks in advance!

Offline

#2 2009-03-11 13:51:37

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Some problems with conditional tags in 4.0.8

From the README.TXT:

Changed tag: <txp:if_category name=”“> is now FALSE on a category page (old behaviour is preserved on upgrades).

HTH.

Offline

#3 2009-03-11 14:40:55

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Some problems with conditional tags in 4.0.8

rsilletti wrote:

Single quotes are required for parsing tags as attributes:
These:
<meta name=“description” content=”<txp:custom_field name=“meta_desc” />” />
<meta name=“keywords” content=”<txp:keywords />” />

Should be written this way:
<meta name=“description” content=’<txp:custom_field name=“meta_desc” />’ />
<meta name=“keywords” content=’<txp:keywords />’ />

rsilletti, you do realize that those are XHTML tags and not Textpattern tags within Textpattern tags. Thus making your suggestion wrong, as TXP tags are clearly parsed when used as values of XHTML attributes. That single quote parsing rule is just for <txp:tags /> attribute parsing.

Shortly said, no need to change those.

Last edited by Gocom (2009-03-11 14:43:38)

Offline

#4 2009-03-11 15:26:20

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Some problems with conditional tags in 4.0.8

Oops, nope Thanks for the heads up.

Offline

#5 2009-03-11 15:32:27

sipke
Member
From: In a Galaxy far far away...
Registered: 2004-06-15
Posts: 16
Website

Re: Some problems with conditional tags in 4.0.8

Thank you guys for the suggestions. As I am not a programmer type, I made a try with a hard-coded value first and checked the tag tracer.
My code looks like this now:

<txp:if_category name=“tips-and-tricks”>
<txp:article form=“meta_dynamic” status=“hidden” />
</txp:if_category>

I navigated to the given category page on the website, and the source is as follows in the tag trace:

...
<txp:if_section name="">
		[<txp:if_section name="">: false]
		<txp:if_category name="tips-and-tricks">
			[<txp:if_category name="tips-and-tricks">: true]
			<txp:article form="meta_dynamic" status="hidden" />
				[SQL (0.00050711631774902): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() 
and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (Category1 IN ('tips-and-tricks') or Category2 IN ('tips-and-tricks'))
 and Section IN ('articles')]
				[SQL (0.00067901611328125): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as 
uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= 
Expires or Expires = '0000-00-00 00:00:00') and (Category1 IN ('tips-and-tricks') or Category2 IN ('tips-and-tricks')) and Section IN 
('articles') order by Posted desc limit 0, 10]
.............

Why is the SQL selection for Status=4 (live) when it should select the articles with Status=2 (hidden)?

I’m lost now, and sorry for being such noob, but I can’t understand what I do wrong now as the if_category tag is now returns with true.

Thanks in advance :)

Offline

#6 2009-03-11 20:34:42

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

Re: Some problems with conditional tags in 4.0.8

As far as I understand the code (it has changed since 4.0.7), if status is not sticky, it is always live. So that would mean that you can’t use status="hidden" anymore. (Coders, correct me if I’m wrong!)
Is there a reason why you can’t use a sticky article here as well?

There is another way to do it for category pages (I’ve used it before myself): put your meta data in a (misc) form for each category, and name the form exactly like the category. You can then use

<txp:if_category>
<txp:output_form form='<txp:category />' />
</txp:if_category>

I can’t understand what I do wrong now as the if_category tag is now returns with true.

No, I don’t think that is related.

Last edited by els (2009-03-11 20:35:54)

Offline

#7 2009-03-11 21:01:55

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Some problems with conditional tags in 4.0.8

Els wrote:

As far as I understand the code (it has changed since 4.0.7), if status is not sticky, it is always live. So that would mean that you can’t use status="hidden" anymore. (Coders, correct me if I’m wrong!)

Correct. I’ll reinvestigate this behaviour with this very special use case in mind.

Offline

#8 2009-03-11 21:02:15

sipke
Member
From: In a Galaxy far far away...
Registered: 2004-06-15
Posts: 16
Website

Re: Some problems with conditional tags in 4.0.8

Ahh, thanks Els, that could be the problem then!
I cannot use sticky because sticky is used at the sections and my categories are linked to the sections and therefore I would have 2 stickies for TXP to chose from on the category pages. Or is there a workaround? (I have tried it now and my category pages contain both sticky article data. :(

So it seems there is no way to manipulate hidden/pending/draft articles on the frontend anymore?

Offline

#9 2009-03-11 21:58:22

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

Re: Some problems with conditional tags in 4.0.8

sipke wrote:

Or is there a workaround?

You could also create a special category (or more) for these articles, and use <txp:article_custom category="special-category" />.

So it seems there is no way to manipulate hidden/pending/draft articles on the frontend anymore?

That’s right. But wet just said:

I’ll reinvestigate this behaviour with this very special use case in mind.

Last edited by els (2009-03-11 22:01:05)

Offline

#10 2009-03-11 22:44:46

sipke
Member
From: In a Galaxy far far away...
Registered: 2004-06-15
Posts: 16
Website

Re: Some problems with conditional tags in 4.0.8

Many thanks for the help :)

Offline

Board footer

Powered by FluxBB