Jump to content


Photo

Get children of current document


  • Please log in to reply
2 replies to this topic

#1 PaulD

PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 413 posts

Posted 23 April 2010 - 09:16 PM

I am trying to get the active children of the current document. What is the easiest way to do this?

At the moment I have started with

// get id of current document
$id = $etomite->documentIdentifier;

// get data of current document
$data = $etomite->getPageInfo($id, $active=1, $fields='id, pagetitle, longtitle, parent, alias');

// sort data I want into strings (I know I dont really need to do this bit)
$pagetitle = $data['pagetitle'];
$parent = $data['parent'];

I planned to use getChildren or similar but then found that getAllChildren gets all children in a two dimensional array, not just the current documents children. Should I just use this and extract the current document information or should I do my own getIntTables where parent=$data['parent'] type of thing.

I suppose both methods would work but which is the best or the more efficient method?

Thanks in advance for any help or advice,

Paul.

EDIT In the end I did it with the getIntTables route and it is working fine. I reasoned that the more limited search must be more efficient as it pulls in less data. Any time differences would probably be totally unnoticeable anyway.

Edited by PaulD, 24 April 2010 - 01:19 AM.


#2 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 24 April 2010 - 12:53 PM

Paul, try using getActiveChildren()... This API function skips unpublished, deleted, and hidden documents... Results are returned as an array structure... I just nticed that the documentatin site needs to be updated to include the $showhidden flag... Several of the original snippets are stil using getAllChildren() when they could use getActiveChildren() more gracefully...

 function getActiveChildren($id=0, $sort='menuindex', $dir='', $fields='id, pagetitle, longtitle, description, parent, alias, showinmenu', $limit="", $showhidden=false) {
 // returns a two dimensional array of $key=>$value data for active documents only
 // $id = id of the document whose children have been requested
 // $sort = the field to sort the result by
 // $dir = sort direction (ASC|DESC)
 // $fields = comma delimited list of fields to be returned for each record
 // $limit = maximun number of records to return (default=all)
 // $showhidden = setting to [true|1] will override the showinmenu flag setting (default=false)


#3 PaulD

PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 413 posts

Posted 24 April 2010 - 04:35 PM

Thanks Ralph,

I shall give it a go. It is working with getInt tables function now but I have not used getActiveChildren before. Thanks again,

Paul.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users