foreach variations

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 3, 2008   (RSS)

By rez - December 2, 2008 - edited: December 2, 2008

Hello. I need to list specific records in groups on one page. In the code generator, i only see how to list all or a a certain number of records. Here is what I am trying to recreate:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<root>

<collection title="2008">
<news>
<date>25.10.2008</date>
<text>
<![CDATA[This is Dynamic HTML text from external XML file. ]]>
</text>
</news>
<news>
<date>20.10.2008</date>
<text>
<![CDATA[This is Dynamic HTML text from external XML file. ]]>
</text>
</news>
</collection>
<collection title="2007">
<news>
<date>25.10.2007</date>
<text>
<![CDATA[This is Dynamic HTML text from external XML file. ]]>
</text>
</news>
</collection>
<collection title="2006">
<news>
<date>25.10.2006</date>
<text>
<![CDATA[This is Dynamic HTML text from external XML file. ]]>
</text>
</news>
</collection>
</root>

Re: [rez] foreach variations

By Dave - December 3, 2008

Hi rez,

I'm not sure what your content is, but one way to do it would be to let your clients enter the collection_title. Either by having it be a text field or making it a list field that loads from another section "Collection Titles" that only has fields for num and name.

Once that is working, you can have your viewer sort by collection_title like this:

'orderBy' => 'collection_title',

And then only show the first instance of each section_title with the code in this post:
http://www.interactivetools.com/forum/gforum.cgi?post=64795#64795

Then all the records in that section after. Hope that makes sense. Let me know if you have more questions about that.

The $newsMetaData contains extra information about the list of records that was returned such as page number, etc. You can see what it contains (or any other PHP variable for that matter) with this code:

<xmp><?php print_r($newsMetaData) ?></xmp>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com