Last 5 articles in a nested hierarchy?

Author Message

arthur foelsche

Wednesday 16 April 2003 1:44:02 pm

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

Paul Borgermans

Wednesday 16 April 2003 1: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_3/documentation/ez_publish_3/howtos/how_to_fetch_function_parameters_and_examples

Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

arthur foelsche

Wednesday 16 April 2003 2: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 :)

arthur foelsche

Wednesday 16 April 2003 2: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}

Paul Borgermans

Thursday 17 April 2003 4:44:58 am

>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

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Sergiy Pushchin

Wednesday 23 April 2003 1: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.

Jørgen Skogstad

Saturday 03 May 2003 3:25:29 am

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 15:02:15
Script start
Timing: Jan 18 2025 15:02:15
Module start 'layout'
Timing: Jan 18 2025 15:02:15
Module start 'content'
Timing: Jan 18 2025 15:02:15
Module end 'content'
Timing: Jan 18 2025 15:02:15
Script end

Main resources:

Total runtime0.0144 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.1484152.6406
Module start 'layout' 0.00570.0025 741.789139.4766
Module start 'content' 0.00820.0044 781.265697.3359
Module end 'content' 0.01260.0017 878.601638.3047
Script end 0.0143  916.9063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002718.6499140.0002
Check MTime0.00128.0473140.0001
Mysql Total
Database connection0.00074.944810.0007
Mysqli_queries0.002819.552030.0009
Looping result0.00000.082910.0000
Template Total0.00139.410.0013
Template load0.00074.764010.0007
Template processing0.00074.589910.0007
Override
Cache load0.00053.407610.0005
General
dbfile0.00096.052580.0001
String conversion0.00000.034840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs