Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-12-08 19:48:59

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Output sticky articles first in an article list

Hello all + Snow.

Besides here’s my very simple question:

In a an article list page how to output the first sticky article encountered, else output a live article ?
Or
Why this below always returns VALUE even if no sticky article exists.

<txp:if_article_list>
<txp:article_custom category='<txp:category />' section="ladies" status="sticky">
<txp:variable name="art_bodydesc" value="<txp:body />" /></txp:article_custom>
<txp:if_variable name="art_bodydesc" value="">NOVALUE
<txp:else />VALUE
</txp:if_variable>
</txp:if_article_list>

Scratching my head right now…

Last edited by hablablow (2010-12-08 19:50:47)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#2 2010-12-08 20:02:26

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

Re: Output sticky articles first in an article list

<txp:variable name="art_bodydesc" value="<txp:body />" /></txp:article_custom>

When nesting txp tags inside txp tags, you have to escape use single quotes, like this:

<txp:variable name="art_bodydesc" value='<txp:body />' /></txp:article_custom>

Anyway, I don’t think this approach to the problem you are trying to solve will lead you to success.
I’ve created a pastebin for you. Check it here: http://pastebin.com/CpR2c1FP


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2010-12-08 20:11:26

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

Received your pastebin Julián via Twitter. I’m on it and it seems to work. I’ll come back later to paste it in here…
And yes my solution didn’t work at all…
Muchas gracias !

Last edited by hablablow (2010-12-08 20:12:04)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#4 2010-12-08 21:47:10

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

Alright here it goes, Julián your solution is perfectly working, very clever…

Simply pasted from the link in Julián’s post:

<txp:if_article_list>
  <txp:variable name="stickies_exist"><txp:article status="sticky" limit="1">(dummy text)</txp:article></txp:variable>
  <txp:if_variable name="stickies_exist" value="">
    <txp:article status="live" />
  <txp:else />
    <txp:article status="sticky" />
  </txp:if_variable>
</txp:if_article_list>

_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#5 2010-12-08 21:51:35

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

Scratching my head on another second level issue now…

How do I apply the same mechanism inside the filter above but to check if an article as an image ? And if not skip to the next article that has an image….

<txp:if_article_list>
  <txp:variable name="stickies_exist"><txp:article status="sticky" limit="1">(dummy text)</txp:article></txp:variable>
  <txp:if_variable name="stickies_exist" value="">
<txp:variable name="art_img"><txp:article limit="1"><txp:article_image /></txp:article></txp:variable>
<txp:if_variable name="art_img" value="">NOIMG
<txp:else />IMG
    <txp:article status="live" />
  <txp:else />
    <txp:article status="sticky" />
  </txp:if_variable>
</txp:if_article_list>

Of course this is working. The current viewed live article has no image ! But then how do I output the next article that has an image and not stay trapped in the NOIMG cage ?

Last edited by hablablow (2010-12-08 21:55:44)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#6 2010-12-09 08:20:14

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

Re: Output sticky articles first in an article list

<txp:if_article_list>
	<txp:variable name="stickies_exist"><txp:article status="sticky" limit="1">(dummy text)</txp:article></txp:variable>
	<txp:if_variable name="stickies_exist" value=""><!-- live article -->
		<txp:article limit="1">
			<txp:variable name="art_img"><txp:article_image /></txp:variable>
			<txp:if_variable name="art_img" value="">
				// no article image
			<txp:else />
				// there is an article image
			</txp:if_variable>
		</txp:article>
	<txp:else /><!-- sticky article -->
		<txp:article status="sticky" limit="1">
			<txp:variable name="art_img"><txp:article_image /></txp:variable>
			<txp:if_variable name="art_img" value="">
				// no article image
			<txp:else />
				// there is an article image
			</txp:if_variable>
		</txp:article>
	</txp:if_variable>
</txp:if_article_list>

Offline

#7 2010-12-09 12:08:57

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

Thank you Els….
But I end up with the same result, still jailed in the first /*no article image*/ which is always true since the most recent, last live article has no image.
And of course I’d like to skip this and go to the next available live article with an image…
Am I missing something obvious here ?

Last edited by hablablow (2010-12-09 13:22:39)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#8 2010-12-09 13:44:42

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Output sticky articles first in an article list

I think what you want is: if there are sticky articles, show one of those. If not, show the first article with an image. Does that cover everything? If so, one solution is soo_article_filter, which allows you to select only articles with assigned images.

You could do this without a plugin, by selecting a large set of articles (limit="9999"), assigning a variable to act as a flag saying whether or not you’ve found the article yet, then looping through the articles. Check the flag at the top of the loop. If no image, output nothing. If an image, output the article form you want, then set the flag to true. No plugin, but horribly inefficient.


Code is topiary

Offline

#9 2010-12-09 14:22:10

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

… if there are sticky articles, show one of those. If not, show the first article with an image…

Exactly Jeff.

Thanks for pointing the plugin, but I’d like to see first if managing this issue throught txp tags is possible.

Shouldn’t be that complicated, just don’t display in an article list, where only one article is shown, an article that has no img and skip to the next one with an image… Without building a giant variable…

Last edited by hablablow (2010-12-09 14:23:23)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#10 2010-12-09 15:22:08

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Output sticky articles first in an article list

The variable itself isn’t large, it’s the article limit="9999" that is less than ideal, if all you’re after is a single article. Admittedly, my plugin isn’t ideal from a memory management point of view either. (Gives me an idea for a plugin update, though.)

I think it would work to replace this part of Els’s code:

<txp:article limit="1">
	<txp:variable name="art_img"><txp:article_image /></txp:variable>
	<txp:if_variable name="art_img" value="">
		// no article image
	<txp:else />
		// there is an article image
	</txp:if_variable>
</txp:article>

with this:

<txp:variable name="art_img" value="" /> <!-- Edit: need to initialize the variable -->
<txp:article limit="9999">
	<txp:if_variable name="art_img" value="">
		<txp:if_article_image>
			// article output tags here
			<txp:variable name="art_img" value="1" />
		</txp:if_article_image>
	</txp:if_variable>
</txp:article>

It’s a brute force method; it will iterate over every article in the db. You could reduce the limit value if you were certain of finding an article within that limit.

Last edited by jsoo (2010-12-09 16:08:22)


Code is topiary

Offline

#11 2010-12-09 15:43:30

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Output sticky articles first in an article list

Thank you Jeff but as I can’t figure out how many articles I will have + iterating over the whole db isn’t bullet proof unfortunately, as you suggested as well…

Damm !

Help !


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#12 2010-12-09 16:09:16

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Output sticky articles first in an article list

Just tested my code and it doesn’t work. Have to initialize the variable first. I’ve edited the post so that the code now works.

Last edited by jsoo (2010-12-09 16:09:35)


Code is topiary

Offline

Board footer

Powered by FluxBB