Forums / Setup & design / Last 5 articles in a nested hierarchy?

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

eZ debug

Timing: Jan 29 2025 14:38:39
Script start
Timing: Jan 29 2025 14:38:39
Module start 'content'
Timing: Jan 29 2025 14:38:39
Module end 'content'
Timing: Jan 29 2025 14:38:40
Script end

Main resources:

Total runtime0.2445 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 588.0469180.8281
Module start 'content' 0.00730.0061 768.8750101.8984
Module end 'content' 0.01340.2311 870.7734531.3281
Script end 0.2444  1,402.1016 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00291.1798200.0001
Check MTime0.00120.4827200.0001
Mysql Total
Database connection0.00070.285910.0007
Mysqli_queries0.199781.65231410.0014
Looping result0.00120.47131390.0000
Template Total0.230894.410.2308
Template load0.00070.291210.0007
Template processing0.230094.080710.2300
Override
Cache load0.00050.186910.0005
Sytem overhead
Fetch class attribute can translate value0.00060.239710.0006
XML
Image XML parsing0.00020.083910.0002
General
dbfile0.00923.7546200.0005
String conversion0.00000.002930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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