This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Setup & design » Last 5 articles in a nested hierarchy?
expandshrink

Last 5 articles in a nested hierarchy?

Last 5 articles in a nested hierarchy?

Wednesday 16 April 2003 10:44:02 pm - 6 replies

Hi-

I'm developing a news site and am trying to figure out how to pull the latest stories out of a nested hierarchy.

For example the hierarchy might look something like:

A
-1
--a
--b
--c
-2
--d
--e
---
---3
--f
---4
----g
----h
----i

etc.

what kind of syntax do i need to walk the hierarchy and grab the latest 5 stories? Is there a good place to look for code snipets? I've checked these forums and the wiki, but there isn't anything that i can find that seems to do it.

any one done this before?

arthur

Wednesday 16 April 2003 10:50:27 pm

Nothing special really (no hierarchy walk necessary), its all in the fetch function parameters:

pay special attention to the depth: set it to a large number or choose 0 (this appears to be unlimited depth) and then sort by published (ascending or descending -- try it out) should do the trick.

I used something similar for the forum enhancement. See

http://ez.no/developer/ez_publish...tch_function_parameters_and_examples

Paul

Modified on Wednesday 16 April 2003 10:51:23 pm by Paul Borgermans

Wednesday 16 April 2003 11:12:55 pm

thanks for the fast reply
here's the code snipit that i am using to just traverse the whole list:

{let test=fetch( 'content', 'list', hash(parent_node_id, 159, "sort_by", array("name", true()), "depth", 0)) }
{section name=Child loop=$test}
{node_view_gui view=line content_node=$Child:item}<br>
{/section}

which does work. now i just gotta figure out how to only return the most recent 5 happy.gif Emoticon

Wednesday 16 April 2003 11:26:50 pm

so this is the code that i used to grab the 5 most recent stories. Has there been any thought to developing a code library for snipts of code like this so that newbies (like myself) can easily grab commonly need functions? I think it would be super helpful.

{* change node id 159 to match your node *}
{let test=fetch( 'content', 'list', hash(parent_node_id, 159, class_filter_type, "include", class_filter_array, array(2), "sort_by", array("name", true()), "depth", 0)) }
{section name=Child loop=$test max=5}
{node_view_gui view=line content_node=$Child:item}
<br>
{/section}

Thursday 17 April 2003 1:44:58 pm

>Has there been any thought to developing a code library for
> snipts of code like this so that newbies (like myself) can easily
> grab commonly need functions? I think it would be super helpful.

Well, post your code snippet in the user contributed docs or the "contributions". If many of us do that, we have a code library.

The template system is very powerful; only by providing such real world examples the true power is revealed.

Paul

Wednesday 23 April 2003 10:41:17 am

I think this way is more nice:
fetch(content,list,hash(parent_node_id,16,limit,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array(2)))

you don't need to limit in loop since you are able to limit in fetch function. Another thing you need to sort by published attribute, not name.

Saturday 03 May 2003 12:25:29 pm

Does the last one work with v3.0.2?? I have 3.0.2 on my laptop which works.. but my hosted on v3.0.1 .. it does not .. for some strange reason .. perhaps a typo, but I have redone this several times now already!

Kindest,
Jørgen Skogstad

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from