Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-04-16 08:57:18
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Sticky article gets displayed multiple times
I use the following code to display either the individual article or a sticky article if no individual article is selected:
<txp:if_individual_article>
<txp:article form="myFormat" limit="1"/>
<txp:else />
<txp:article category="<txp:category />" status="sticky" form="myFormat" limit="1"/>
</txp:if_individual_article>
If no article is selected, the sticky article gets displayed n times. With n being the number of live articles in the current category. Why is that?
Offline
Re: Sticky article gets displayed multiple times
Please can you post the code for your form, myFormat, and I’ll have a look…
Offline
#3 2010-04-16 12:56:58
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: Sticky article gets displayed multiple times
<p>
<h1><txp:permlink><txp:title /></txp:permlink></h1>
<txp:body />
</p>
It also displays a message saying the comments are closed for this article even though there’s nothing in the form.
Offline
#4 2010-04-16 17:15:27
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Sticky article gets displayed multiple times
bmwg wrote:
<txp:article category="<txp:category />" status="sticky" form="myFormat" limit="1"/>
Remove the category
attribute, <txp:article />
doesn’t use it. If you meant to use <txp:article_custom />
you must use single quotes when using tags as attribute values. I don’t know if that’s the reason the sticky article is displayed ‘n’ times (how many times is that?). If it still happens when you’ve corrected the article tag, can you post a tag trace of the page in question?
It also displays a message saying the comments are closed for this article even though there’s nothing in the form.
In Admin > Preferences, set Automatically append comments to articles to ‘no’.
BTW remove the <p>
tags from your form, it will produce invalid HTML.
Last edited by els (2010-04-16 17:16:21)
Offline
Re: Sticky article gets displayed multiple times
Thanks Els, I was just about to concoct something, but not the same as yours. So if your solution works fine, I’ll leave well alone ;-)
Offline
#6 2010-04-16 19:18:11
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Sticky article gets displayed multiple times
gavnosis wrote:
I was just about to concoct something, but not the same as yours. So if your solution works fine, I’ll leave well alone ;-)
Please keep it stand-by, I’m not sure at all if my post holds the solution… ;)
Offline
#7 2010-04-17 08:47:35
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: Sticky article gets displayed multiple times
Changing the article tag didn’t do it. With ‘n’ times I meant if I have a category with 3 live articles and one sticky the sticky article gets displayed 3 times. n is the number of live articles in a category. Here’s the tag trace for a category with 3 live articles:
(Artikel 7,9,10 are live in that category, Artikel 8 is the sticky one)
<txp:article form="prodArtikel"/>
[SQL (0,000942945480347): 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 ('classic') or Category2 IN ('classic')) and Section IN ('produkte')]
[SQL (0,00171494483948): 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 ('classic') or Category2 IN ('classic')) and Section IN ('produkte') order by Posted desc limit 0, 10]
[Artikel 10]
[SQL (0,001305103302): select Form from txp_form where name='prodArtikel']
[Baustein: prodArtikel]
<txp:if_individual_article>
[<txp:if_individual_article>: false]
<txp:article status="sticky" form="prodArtikelFormat" limit="1"/>
[SQL (0,00125098228455): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 5 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (Category1 IN ('classic') or Category2 IN ('classic')) and Section IN ('produkte') order by Posted desc limit 0, 1]
[Artikel 8]
[SQL (0,00118207931519): select Form from txp_form where name='prodArtikelFormat']
[Baustein: prodArtikelFormat]
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:body />
</txp:if_individual_article>
[Artikel 9]
[Baustein: prodArtikel]
<txp:if_individual_article>
[<txp:if_individual_article>: false]
<txp:article status="sticky" form="prodArtikelFormat" limit="1"/>
[SQL (0,00141382217407): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 5 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (Category1 IN ('classic') or Category2 IN ('classic')) and Section IN ('produkte') order by Posted desc limit 0, 1]
[Artikel 8]
[Baustein: prodArtikelFormat]
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:body />
</txp:if_individual_article>
[Artikel 7]
[Baustein: prodArtikel]
<txp:if_individual_article>
[<txp:if_individual_article>: false]
<txp:article status="sticky" form="prodArtikelFormat" limit="1"/>
[SQL (0,00160384178162): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 5 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (Category1 IN ('classic') or Category2 IN ('classic')) and Section IN ('produkte') order by Posted desc limit 0, 1]
[Artikel 8]
[Baustein: prodArtikelFormat]
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:body />
</txp:if_individual_article>
So I guess for every article in the category the if_individual_article tag gets checked and is 3 times false because of the 3 live articles in the current category, so the txp:else gets executed 3 times. Thus the 3 sticky articles. But why does that code run for every article in the category in the first place?
Offline
Re: Sticky article gets displayed multiple times
I think you should do it the other way round, and check for an individual article last.
However, I’m not entirely clear what the other case is ;-)
If it’s not a single article, what is it?
I think you should be checking if it’s a category first…
And maybe if it is, display a list of articles grouped by category ??
Or, to do what you’ve asked, just display a single sticky article
(I’m just guessing you’ll want access to all of the articles in the category, too)
To recap, in the page, there are the 2 or 3 cases required:
- A single article (status = live)
- A category list + a single, sticky article
- A third option could be to show the sticky article if there’s nothing in the list, something like this
<txp:if_category>
<h3><txp:category title="1" /></h3>
<txp:article limit="15" />
<txp:else />
<txp:if_individual_article>
<txp:article form="myFormat" status="live" />
<txp:else />
<txp:article form="myFormat" status="sticky" />
</txp:if_individual_article>
</txp:if_category>
This is what I’ve used in this example here, to browse by category (and display a single sticky article for the section, in this case); the categories are on the right hand side.
Am I getting closer to your thinking ?
Offline
#9 2010-04-17 12:50:44
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Sticky article gets displayed multiple times
You seem to have an article tag inside an article form. So for every article that is called with the article tag, it also displays a sticky article. Just replace your article tag on the page (<txp:article form="prodArtikel"/>
) with the content of your form ‘prodArtikel’.
Offline
Re: Sticky article gets displayed multiple times
You have the article tag inside an article tag (article list inside article list). If you have three articles in the section, the <txp:article status="sticky"[...]/>
is getting executed three times, thus leading into three articles.
To fix that, you need to move the article tag outside the other article tag. If you are using the tag only to pull form content, then use output_form otherwise just move to it’s own.
PS. I wouldn’t suggest pasting part of the tag trace, whole deal is always better. Rest of it may contain other valuable data and only showing part of it, is going to help noneone.
Edit. Els is faster.
Last edited by Gocom (2010-04-17 12:58:47)
Offline
#11 2010-04-17 20:39:50
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: Sticky article gets displayed multiple times
Thank you all! I replaced the article tag with output_form and now everything works fine.
Offline