Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2015-07-18 06:50:24

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: Randomly ordered images permlinked to their respective articles...

I wouldn’t use comma as separator, because <txp:image /> outputs something like

<img src="http://localhost/textpattern-parser/images/1.png" alt="Comma, why not?" ... />

If some alt text contains comma, things will go west. So, to complete, this is the list (as suggested by Julian, but delimited by |||)

<txp:variable name="list">
  <txp:article_custom limit="200" break="|||">
    <txp:images id='<txp:custom_field name="article_image" />' break="|||">
      <txp:permlink><txp:image /></txp:permlink>
    </txp:images>
  </txp:article_custom>
</txp:variable>

Now, etc_query (once fixed), rah_replace (if it accepts rand() sort, of which there is no evidence) or adi_list (if it accepts custom delimiters…) will all work, but not do any better than my php snippet.

Offline

#12 2015-07-18 07:32:34

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,254
Website

Re: Randomly ordered images permlinked to their respective articles...

etc wrote #293454:

I wouldn’t use comma as separator, because <txp:image /> outputs something like

I don’t think that’s a problem with what I suggested – it runs on article IDs until the last moment, when a link is output.

But if you do need a delimiter with adi_list then use separator="|" or some such and change default_separator to be something different (it defaults to "|").

Last edited by gomedia (2015-07-18 07:36:17)

Offline

#13 2015-07-18 08:10:54

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: Randomly ordered images permlinked to their respective articles...

gomedia wrote #293456:

I don’t think that’s a problem with what I suggested – it runs on article IDs until the last moment, when a link is output.

Sure, but what you suggest either (with limit="1") outputs one image per article, or (without limit) leaves them grouped by article. That’s not what Stacey wants, and you obtain the same result with

<txp:article_custom sort="rand()">
	<txp:if_article_image>
		<txp:images sort="rand()">
			<txp:permlink><txp:image /></txp:permlink>
		</txp:images>
	</txp:if_article_image>
</txp:article_custom>

But if you do need a delimiter with adi_list then use separator="|" or some such and change default_separator to be something different (it defaults to "|").

Good to know, I haven’t found separator attribute on your site.

Last edited by etc (2015-07-18 08:15:05)

Offline

#14 2015-07-18 09:51:19

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,254
Website

Re: Randomly ordered images permlinked to their respective articles...

etc wrote #293459:

Sure, but what you suggest either (with limit="1") outputs one image per article, or (without limit) leaves them grouped by article. That’s not what Stacey wants

Must’ve misunderstood, I thought one random image from one random article was the requirement.

Good to know, I haven’t found separator attribute on your site.

I’ll look into that, thanks.

Offline

#15 2015-07-18 10:16:11

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,897
Website

Re: Randomly ordered images permlinked to their respective articles...

I love it that there are so many different ways to do things. When I first read the question I thought “that’s a tough one”, but our collective input adds more ideas to the pool.

Oleg, you’re right: I had assumed rah_repeat would support sort="rand()". Would need trying…

adi_list is another one I’ve overlooked – must try that out sometime.


TXP Builders – finely-crafted code, design and txp

Offline

#16 2015-07-18 14:36:08

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Randomly ordered images permlinked to their respective articles...

This is something that should be kept on TXP Tips for posterity. But who is the author…?!

Offline

#17 2015-07-18 14:49:53

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: Randomly ordered images permlinked to their respective articles...

jstubbs wrote #293475:

This is something that should be kept on TXP Tips for posterity. But who is the author…?!

Depends on what is this

Offline

#18 2015-07-18 14:51:17

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Randomly ordered images permlinked to their respective articles...

etc wrote #293476:

Depends on what is _this_…

Also..!

Offline

#19 2015-07-18 15:24:51

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: Randomly ordered images permlinked to their respective articles...

Looks like a good occasion to test your “switch author” plugin, Jonathan. ;)

Offline

#20 2015-07-19 00:09:53

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Randomly ordered images permlinked to their respective articles...

But who would be the author Oleg..?!!

Offline

Board footer

Powered by FluxBB