Forums / Setup & design / Fetch nodes from sections?

Fetch nodes from sections?

Author Message

Siniša Šehović

Tuesday 06 December 2005 3:25:45 pm

Hi all!

Is it possible to fetch nodes from specified section?

Best regards,
S.

---
If at first you don't succeed, look in the trash for the instructions.

Ben Peter

Tuesday 06 December 2005 4:08:36 pm

Hi Sinisa,

http://ez.no/doc/ez_publish/technical_manual/3_6/reference/modules/section/fetch_functions/object_list

-- is that what you are looking for? From the object, you can track back to its main node.

Cheers,
Ben

Siniša Šehović

Wednesday 07 December 2005 12:00:44 am

Hi Ben

Thanx for quick reply!

Yes that's what I was looking for :-)

Btw, is it possible to filter object by date of publish and class_id?

Best regards,
S.

---
If at first you don't succeed, look in the trash for the instructions.

Wednesday 07 December 2005 1:54:37 am

Yes it's possible. Here's a complete example from one of my sites:

{* Grab all the news articles. *}
{*
{let children=fetch( content,
                     list,
                     hash( parent_node_id, $node.node_id,
                           sort_by, $node.sort_array,
                           class_filter_type, include,
                           class_filter_array, array( 'article' )
                         )
                    )
}
*}

<h2>2005</h2>
{let year=2005
     firstSecond=maketime(0,0,0,1,1,$year)
     lastSecond=maketime(23,59,59,13,0,$year)
     children=fetch( content,
     list,
     hash( parent_node_id, $node.node_id,
        sort_by, $node.sort_array,
        class_filter_type, include,
        class_filter_array, array( 'article' ),
        attribute_filter, array( 'and', array( 'published', between, array( $firstSecond, $lastSecond ) ) )
        )
     )
}

<table class="news_archive" width="100%">
    <tr>
        <th>
            <b>Artikkeltittel</b>
        </th>
        <th>
            <b>Publisert</b>
        </th>
    </tr>

    {* Loop through all articles that we just fetched. *}
    {section name=Child loop=$children}
    <tr>
        <td>
            {* Display a link to the article. *}
            <a href={$:item.url_alias|ezurl}>{$:item.name}</a>
            <br />
        </td>
        <td>
            {* Display the date the article was published. *}
            {$:item.object.published|l10n(shortdate)}
        </td>
    </tr>
    {* End of loop. *}
    {/section}
</table>

I hope this was what you were looking for.

Wednesday 07 December 2005 1:58:33 am

The code above isn't presented correctly.
Looks like equal signs are being removed in the code field...

Could someone from eZ look into this issue?
The code is correct when i edit my posting....

Siniša Šehović

Wednesday 07 December 2005 2:02:19 am

Hi Hans-Henry,

Thanks for that, but question was for filtering fetched objects from selected section.

How to display only published articles from specified section?

Best regards,
S.

---
If at first you don't succeed, look in the trash for the instructions.

Kristof Coomans

Tuesday 13 December 2005 6:03:08 am

You can filter on 'section' with the 'attribute_filter' array in a 'list' or 'tree' fetch.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Siniša Šehović

Wednesday 14 December 2005 12:01:11 am

Hi Kristof

Could you write some example code for that?

S.

---
If at first you don't succeed, look in the trash for the instructions.

Kristof Coomans

Thursday 15 December 2005 3:41:47 am

{let sectionID=1 
    year=2005
    firstSecond=maketime(0,0,0,1,1,$year)
    lastSecond=maketime(23,59,59,13,0,$year)
    children=fetch( content,
    list,
    hash( parent_node_id, $node.node_id,
       sort_by, $node.sort_array,
       class_filter_type, include,
       class_filter_array, array( 'article' ),
       attribute_filter, array( 'and', 
                                      array( 'published', between, array( $firstSecond, $lastSecond ) ),
                                      array( 'section','=',$sectionID )
                                     )
       )
    )
}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org