Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-11-16 00:55:10

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

[howto] taking advantages of status="live" and status="sticky"

In a section, I have both “sticky” and “live” articles.
I was trying to achieve something simple:

  • when in section frontpage, output the list of “sticky” articles followed by the list of “live” articles.
  • when clicking in the article permlink (sticky or live, it doesnt care), just display the article.

Those are two very simple request.
But the truth is that it took me a bit more than few minutes to arrive to a very simple solution.

The first attemp: the wrong way

My first attempt was wrong.
The code was:

<txp:article form="default" listform="listado" status="sticky" />
<txp:article form="default" listform="listado" />

It worked for the section frontpage (article-list context), but it didn’t work when in individual-article context. Why? because it led to duplicate articles when in “sticky” individual-article context.

The second attempt: the Inefficient way.

This one works. But I dont like it.
It’s a simple solution using some conditional (if_article_list, and if_individual_article) but I had the feeling that it was “inefficient”. I didnt like it at all. And I have the feeling that it would be a simple and efficient way to achieve the same.
The code was:

<txp:if_article_list>
	<txp:article form="default" listform="listado" status="sticky" />
	<txp:article form="default" listform="listado" />
</txp:if_article_list>
<txp:if_individual_article>
	<txp:article />
</txp:if_individual_article>

The last attempt: the Simple and Efficient way

This one works too and I like it. The code is very similar to the first attempt.
The code is:

<txp:article form="default" listform="listado" status="sticky" />
<txp:article form="default" listform="listado" status="live" />

The difference between the first attempt and this last one is that I added a status="live" to the second txp:article tag.
At first, I thought: “Two txp:article tags? This wont work in individual-article context. Again, I will have duplicated articles.
But it worked flawlessly:

  • in article-list context, the snippet outputs the “sticky” articles followed by the “live” articles.
  • in individual-article context, the snippet outputs the article (“sticky” or “live”) once.

the Conclusion.

  • in individual-article context, the status attribute will work as some kind of filter. Well, that makes sense, because it is a filter.
  • in TXP you can achieve same goals in different ways.

Last edited by maniqui (2007-02-14 00:47:10)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2005-11-17 03:15:51

aesop1
Archived Plugin Author
Registered: 2004-09-19
Posts: 142

Re: [howto] taking advantages of status="live" and status="sticky"

Good tip, Maniqui. I have been using the second method by default on a regular basis, this will be nice for shortening up page templates.

Offline

#3 2005-11-17 03:47:37

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: [howto] taking advantages of status="live" and status="sticky"

Very clever, I like it. I wasn’t sure how sticky articles ought to work on individual article pages, so the actual behaviour is a bit arbitrary. Good to see there’s a neat and simple way to wrangle it.


Alex

Offline

#4 2005-11-17 13:45:06

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [howto] taking advantages of status="live" and status="sticky"

Hi! Thanks to both you. I’m glad you like the tip.

zem wrote:

I wasn’t sure how sticky articles ought to work on individual article pages, so the actual behaviour is a bit arbitrary.

Can you explain that “behaviour bit arbitrary”? I didnt found it “arbitrary” (in a “quirk” sense). I find the actual behaviour is inside the “TXP logic”. I mean, “sticky” articles on individual-article context actually work as expected.

My first attemp was wrong because TXP logic makes sense: if I use two txp:article tags, one with an attribute (status=”“ as a filter attribute) and the other one without filter attributes, then in individual-article context, TXP will display two “duplicated” articles, because that is what the tags are telling to do to TXP.

Also, I think my last attemp works because, again, TXP logic makes sense: if I use two txp:article tags, both with a filter attribute (status=”“), then in individual-article context, TXP will go through those tags and will output only the article that match the conditions (= that match the attributes).
So, in the last attempt, one of the txp:article tags is “excluded” when in individual-article.

To conclude: in individual-article, “sticky” articles should work exactly as “live” articles. A simple <txp:article /> (without any filter attribute) should always output the called article (dont care if “sticky” or “live”) when in individual-article context.

Fin.

BTW, zem, could you take a look at this feature request ?

I have another of my “very clever” and “good tip” but I need that feature… ;)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2005-11-17 20:13:35

nasv
Member
Registered: 2005-11-14
Posts: 22

Re: [howto] taking advantages of status="live" and status="sticky"

<p>Che, Maniqui, I want to do almost exactly what you explained, I was wondering if you had input on the following alteration to your requirements<br>
This is the simple thing I want to achieve:<br>
—when in <i>section</i> frontpage, output the list of “sticky” articles ONLY — NO following of live articles.<br>
—when clicking in the article permlink (sticky or live, it doesnt care), just display the article.<br>
</p>

<p>My main difference is that I do NOT want the live articles on the section homepage. If there is another way without using live vs sticky, I am open to that as well. I basically want ONE main article as the ONLY article for a section homepage but I want to be able to link to other articles (permlink) from the same section… any suggestions?</p>

<p>~Nico</p>

Last edited by nasv (2005-11-17 20:20:36)

Offline

#6 2005-11-17 22:43:04

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [howto] taking advantages of status="live" and status="sticky"

Che, nasv! ;) I was replying to you in the topic you opened in “How do I…?”… but then, I saw you delete it before I post my answer! In that moment, I have the “feeling” that you delete because you found this post.

First, in the other thread (the one you deleted) you said that you were trying to use a “sticky” article to output a list of the other articles (the “live” articles).
I would suggest: dont do it in that way. I mean, dont use a “sticky” article with an txp:article_custom inside to output the “live” article list (that is what you were trying in the snippet 2 of your deleted thread).

That job is supposed to be done by a form (Presentation -> Forms). But if you insist to use an “sticky” article, well, we will try two different methods. One using a simple form and one using with a “sticky” article as you want.

Let’s start.

Method A: using a simple form.

If my memory isnt bad, you wanted to output something like:
“Blablabla
Visit the following articles:
“live” article 1
“live” article 2
“live” article 3
blabla”

1. Go to “Presentation -> Forms” and create a new form named “live_article_list”. (Give it the name you want; also, save it as “misc” or “article”, it’s the same, that option is just for categorization, doesnt affect the functionality of the form) with the following snippet

<del>
"Blablabla
Visit the following articles:
<txp:article form="myarticleform" listform="mylistform" />
blabla"
</del>

edit: this is the correct:

<txp:if_article_list>
Blablabla
Visit the following articles:
</txp:if_article_list>
<txp:article form="myarticleform" listform="mylistform" />

The form “mylistform” should have those article tags (txp:title, txp:body, txp:permlink, etc) that you want to display in your “live” article list.

2. in your page template, simple put this tag where you want to display your “live” article list:
<txp:output_form form="live_article_list" />

3. create some “live” articles and tell me us it works.

Method B: using an “sticky” article.
Do you still want to use a “sticky” article to do the job? Here, we have two options too.

-Option 1:

1. create your “sticky” article with the content you want. Include inside the article body:
<txp:article status="live" form="myarticleform" listform="mylistform" />

note: I dont know if that is going to work, because I rarely use txp tags inside articles. I know some txp tags works inside the article and many others doesnt work.

Remember also to create the form “mylistform” (the same as above)

2. in your page template, add:

<txp:if_article_list>
&nbsp;&nbsp;&nbsp;&nbsp; <txp:article status="sticky" limit="1" />
</txp:if_article_list>
<txp:if_individual_article>
&nbsp;&nbsp;&nbsp;&nbsp; <txp:article />
</txp:if_individual_article>

3. create some “live” articles and tell us if it works.

-Option 2
this is a merge between Method A and Option B.

I will only put the step 2.

2. In your page template, add:

<txp:if_article_list>
&nbsp;&nbsp;&nbsp;&nbsp; <txp:article status="sticky" limit="1" />
&nbsp;&nbsp;&nbsp;&nbsp; <txp:output_form form="live_article_list" />
</txp:if_article_list>
<txp:if_individual_article>
&nbsp;&nbsp;&nbsp;&nbsp; <txp:article />
</txp:if_individual_article>

Of course, now, the content of your “sticky” article can be only text, with no-need of using txp tags inside.

I wrote this a bit quickly, so if there is something that you didnt understand, let me know.

Chau, che!


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2005-11-18 00:23:28

nasv
Member
Registered: 2005-11-14
Posts: 22

Re: [howto] taking advantages of status="live" and status="sticky"

<p>Che! Gracias por la respuesta rapida!</p>
<p>I really appreciate this. For <b>Method A</b>, I agree that Method A (using output_form) seems more logical, but the reason I did not want to do that is b/c I don’t want that information to appear on all the pages of that section, only on the homepage of that section. With a permlink coming from the form, it will open the article page? Do I need a [txp:article /] tag somewhere in this page template (I worry because I thought it was necessary, but I don’t want articles to appear on the front page… these questions and clarifications come to my head as I was thinking about it!)?</p>
<p>I will try the suggestion using the conditionals… I think that will work, I had not anticipated it’s use and was confused with how the documentation explained the conditionals. I will update when I get this working! </p>

<p>Thank you very much,<br>~Nico</p>
<p>p.d. por un rato yo vivia en la esquina de Suipacha con Av. Cordoba en el microcentro… que ciudad tan increible Bs.As.</p>

Offline

#8 2005-11-18 00:39:52

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [howto] taking advantages of status="live" and status="sticky"

I really appreciate this. For Method A, I agree that Method A (using output_form) seems more logical, but the reason I did not want to do that is b/c I don’t want that information to appear on all the pages of that section, only on the homepage of that section. With a permlink coming from the form, it will open the article page? Do I need a [txp:article /] tag somewhere in this page template

Ups! My mistake in the post. I forgot to put < code /> and the code wasnt showing. Read again Method A.
But I also made a mistake in the code. You are right, the information in the form wil show up in the section frontpage and in each article, and that is what you dont want. Sorry, that was my fault.

So, see if this work (you can put this in a form and call it with txp:output_form or directly in the page template:

<txp:if_article_list>
Blablabla
Visit the following articles:
</txp:if_article_list>
<txp:article form="myarticleform" listform="mylistform" />

That should work. The conditional means: “if we are in an article-list (article-list=section-frontpage), display this”.
Then, we simple add the txp:article to call articles. When you are in individual-article context, the conditional wont output anything, and you will simple have the txp:article output, that is, your individual article.

Let me know if that works.

pd: Suipacha y Córdoba! in middle of the centre of Bs. As. What were you doing in this comics city?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#9 2005-11-18 04:58:46

nasv
Member
Registered: 2005-11-14
Posts: 22

Re: [howto] taking advantages of status="live" and status="sticky"

<p>
maniqui, thanks again for your replies… unfortunately, I’m still having trouble understanding, so I thought I’d explain my issue a little more. I have a section in my site called ARTISTS where when I arrive at mydomain/Artists, I want to see my 1 main article (or text from template) that explains a little about the music and then a list of links for articles, like you say:<br>
Blablabla – estos son los artistas:<br>
Artista 1 (permlink to artist)<br>
Artista 2 (permlink to artist)<br>
<br>
I set up categories so that the “Artista 1” and “Artista 2” are in category Artistas, and then I will have articles specific to the artist (and in a sub category named after the artist, like category “Artista1” within those pages that I want to link to like:<br>
This is the artist, learn more:<br>
Biography (permlink to biography)<br>
Compositions (permlink)<br>
<br>
Currently the code I tried from combining some ideas you gave me is below, and on the top main articles like the section home, I use a form by calling:<br>
<code>
Visit the current list of artists produced by Tinto Records:
<txp:article_custom form=“article_link_title” listform=“article_link_title” category=“Artistas” />
</code>
<br>
</p>
<p>
The problem I am having is that when I create a list of links in the Artist1 article (like for biography, compositions), the Artist1 link disappears from the list on the section home, and that confused me. Maybe it has to do with the if statement in the page template (list vs individual article influences my form where I have multiple articles as links with their title)?
</p>

<p>Also, thanks again for the code examples, but I had a question about the snippet you gave me that I should put in the page template:<br>After you put “Visit the following articles” should I put the list of the permlinks within the if or outside? I was confused by that code b/c it looks like that either the links are going to appear always or that even on the homepage of the section I will get the other articles.</p>
<p>MIL gracias por su paciencia! I appreciate your help so much and I like when you explain the code also, it helps me understand more <i>how</i> and <i>why</i> everything works the way it does.<br>Mil gracias,<br>~Nico</p>

<p>I am trying the following in the SECTION page template:
<code>
<txp:if_article_list> <txp:article status=“sticky” limit=“1” form=“Only_Article_Text” listform=“Only_Article_Text” />
</txp:if_article_list>
<txp:if_individual_article> <txp:article form=“Only_Article_Text” />
</txp:if_individual_article>
</code></p>

<p>The code for the “article_link_title” form is:
<code><a href=”<txp:permlink />” title=”<txp:title />” ><txp:title /></a><br></code></p>

Last edited by nasv (2005-11-18 05:00:37)

Offline

#10 2005-11-18 05:25:02

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [howto] taking advantages of status="live" and status="sticky"

Hi nasv. :(
Take it easy. I have no doubt that you will “get it” soon.
Right now, I’m about to going to sleep.

But I leave you some links that maybe will help you. Maybe, you already read them. But I can say something: “better than to read, is to re-read”

I have no doubt that if you read and re-read those faqs and practice some of the code posted there, you will make an “insight” into TXP (you will hear a “click” in your head, and a world plenty of possibilities is ahead that “click”).

If not, I will come back here tomorrow and we will keep searching the way to achieve what you want.

Bye!


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2005-11-18 19:08:34

nasv
Member
Registered: 2005-11-14
Posts: 22

Re: [howto] taking advantages of status="live" and status="sticky"

<p>Che, gracias — I had seen some of those articles and some I had not seen. I started playing around with conditionals and I think I discovered a weirder problem for what I am trying to achieve.<br>—First, here is the code for the section page templage:</p>

<p><code>
<!— RULES FOR DISPLAYING ARTICLES —>
<txp:if_article_list> <!— execute on section home, LIST of articles —> <!— display only the sticky article —> <txp:article status=“sticky” limit=“1” form=“Only_Article_Text” listform=“Only_Article_Text” /> in IF statement
<txp:else /> <!— display when only ONE article is being referred —> <txp:article form=“Only_Article_Text” /> in ELSE statement
</txp:if_article_list>
</code></p>

<p>In the sticky article text, I have the following:<br>
<code>
Blah blah blah
Visit the current list of artists produced by Tinto Records:
<txp:article_custom category=“Artistas” />
<!— TESTING: removed attribute for form=article_link_title —>
</code>
</p>

<p>
So, I have 2 articles with category ARTISTS that should be displayed at the end (within) the sticky article above. One of them called Artist1 has only text and it appears fine; the other article called Artist2 has text and also ANOTHER set of article links in the similar format as above (using article_custom and category attribute), BUT it appears WEIRD.<br>The actual display of the original sticky article becomes:<br><br>
Blah blah blah
Visit the current list of artists produced by Tinto Records:<br>
Artist1 – 15 hours ago by Author<br>
TEXT
<br>————<br>
- 13106 days ago by – -<br>
TEXT<br>
links correctly displayed
<br>——-<br>
</p>
The issue is interesting, when that article contains the permlinks (articles), the heading is all messed up and shows similar to what I have above; but if I take out the article links and just have text, it will show up fine. I know I’m a newb, but it looks like buggy behavior.
<p>

<p>
<b>Edit:</b> I am noticing that there is some sort of problem specifically with displaying articles (permlink) that also contain articles (permlinks) themselves… I tried NOT using a sticky and in the main IF statement and using output_form instead and the behavior was the same… very weird!
</p>

<p>Any ideas?<br>~Nico<br><b>www.tintorecords.com/Artists/</b><br></p>
</p>

Last edited by nasv (2005-11-18 19:29:56)

Offline

#12 2005-11-19 07:01:33

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [howto] taking advantages of status="live" and status="sticky"

Hi Nasv.

I am noticing that there is some sort of problem specifically with displaying articles (permlink) that also contain articles (permlinks) themselves…

I will discourage you about using an “sticky” article including another txp tag inside. As I said before, it’s possible to use some tags inside articles, but I doubt that txp:article or txp:article_custom will behave as expected when inside an article.
And you are not only using it inside an article, but inside an article that also calls another article with a txp:article_custom inside.

Weird behaviour should be expected when doing that kind of things.
(Please, _any developer could confirm or add a note about what I am saying?)

I’m not saying that you are wrong, maybe you are discovering new cool things about how to use TXP that nobody knows.

As I said, soon, you will hear that “click” inside your head…

Taking your code posted above, again, a better approach will be:
<code>
<!— RULES FOR DISPLAYING ARTICLES —>
<txp:if_article_list>
<!— execute on section home —>
<!— display only the sticky article —>
<txp:article status=“sticky” limit=“1” form=“Only_Article_Text” listform=“Only_Article_Text” />
Visit the current list of artists produced by Tinto Records:
</txp:if_article_list>
<!— display “live” articles list when in article-list context (section homepage) and display a individual article when in individual-article context —>
<txp:article form=“Only_Article_Text” />
</code>

The conditional means: if in article-section, display the “sticky” and the “Visit the current…” chunk of text.
Then, the txp:article means: in article-list, show live articles for this section, and when in individual-article, simple show the called article.

In the sticky article, just write:

“Blablabla this is the content for the article that I will show only in the frontpage.”

Maybe, you dont want an “sticky” article to do this, and so, my code above could be:

<p><code>
<txp:if_article_list>
<!— execute on section home —>
<!— display this chunk of text as an introduction for the section —>
Blah blah blah
Visit the current list of artists produced by Tinto Records:
</txp:if_article_list>
<!— display “live” articles list when in article-list context (section homepage) and display a individual article when in individual-article context —>
<txp:article form=“Only_Article_Text” />
</code></p>

Note that I dont use the <txp:else /> nor <txp:if_individual_article>
That’s because I want txp:article <txp:article form="Only_Article_Text" /> to be parsed both in article-list and in individual-article.

And finally, you also have the txp:related_articles tag.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB