I tried to get a random child’s title from a page using this code, but
it
doesn’t work because it gives the title of the current page and not of
the
child. Is there a way to get a random page?
<r:random>
<r:children:each>
<r:option><r:title /></r:option>
</r:children:each>
</r:random>
Does this work?
<r:children:each limit=“1”>
<r:random>
<r:option><r:title /></r:option>
</r:random>
</r:children:each>
That would be grabbing one random title from children pages, correct?
I haven’t tried it myself, so I might be wrong.
Erik M.
The code you wrote should grab the title of the first child (in a list
made
by all the children ordered in ascending order by published_at).
2006/9/13, Erik M. [email protected]:
Ah. So something like this? If such a thing would work.
<r:random limit=“1”>
<r:children:each>
<r:option><r:title /></r:option>
</r:children:each>
</r:random>
Unfortunately that is the same code I posted
(except for the limit
attribute of random, that doesn’t exist).
2006/9/13, Erik M. [email protected]:
Yeah, I wrote that in a rush before leaving work and realized it a few
minutes later. Sorry!
Erik
I’ve been following this thread, but haven’t replied yet. The problem
may
be a tag scoping issue, and maybe a custom tag is in need here.
tag “children:random” do |tag|
children = tag.locals.children
if children.size > 0
index = rand(children.size)
tag.locals.page = children[index]
tag.expand
end
end
Then in your page, write
<r:children:random /><r:title /></r:children:random>
or just
<r:children:random:title />
This will only select one child page, mind you, and would need to be
modified to select more than one.
Cheers,
Sean C.
seancribbs.com
On 14/09/06, Sean C. [email protected] wrote:
end
Then in your page, write
<r:children:random /><r:title /></r:children:random>
or just
<r:children:random:title />
This will only select one child page, mind you, and would need to be
modified to select more than one.
I’ve added this to the wiki at
http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags
–
Regards,
Dave
On 14/09/06, Sean C. [email protected] wrote:
FYI Peek at the weblog… http://radiantcms.org/blog/
That is awesome!
Thank you!
–
Regards,
Dave