Get List of Pages (Including Child) for a Particular Location

edited January 2014 in Share
Hi There,

How can I achieve a list of pages including child for a particular location (eg: our-form, our-firm/contact, our-firm/about etc..)

Thanks in advance.

Comments

  • edited 8:15AM
    If you want to do it statically, add the following to the fuel/application/views/_variables/nav.php
    $nav['our-firm'] = array('label' => 'Our Firm'); $nav['our-firm/contact'] = array('label' => 'Contact', 'parent_id' => 'our-firm'); $nav['our-firm/about'] = array('label' => 'About', 'parent_id' => 'our-firm');

    Then in your view, use the following:
    echo fuel_nav(array('parent' => 'our-firm'))
    This will not include the "Our Firm" menu item since it starts there and looks at that menu items children.

    You can upload that nav.php file in the Navigation module to make it editable in the CMS.

    More on navigation can be found here:
    http://docs.getfuelcms.com/general/navigation
  • edited 8:15AM
    Hi,

    if you want to create a sub-set menu, you can use fuel_nav() with the 'parent' key set to the root branch of your menu eg:

    fuel_nav(array('parent' => 'our-firm'));

    That would show any menu items under "our-firm", but not "our-firm" itself.
  • edited 8:15AM
    Well, thank you so much for your answer but this is not what i am looking for. What i am looking is to loop through our-firm parent id and fetch all child pages and get their 'Excerpt', Featured Image, etc so that i can loop and display as a block and featured in homepage. Hope you get me.

    Thank you
    Anunay
  • edited January 2014
    You would need to use the model to grab all child pages, loop through them, then grab their variables like so:
    $root = 'our-firm'; $CI->fuel_pages_model->db()->like('location', $root.'/', 'after'); $children = $CI->fuel_pages_model->find_all_assoc('location'); $featured_images = array(); foreach($children as $location => $child){ $child_var = $CI->fuel_pagevariables_model->find_one_by_page_id($child->id, 'featured_image'); $featured_images[$location] = $child_var; } print_r($featured_images);
  • edited 8:15AM
    This makes a perfect sense. :) Thank you so much :)
  • edited January 2014
    Hi There,

    I checked implementing the code but i see the following issue. Please help:
    Error: http://d.pr/i/CXTr
    Code To produce error: http://d.pr/i/cCpJ

    Also tried the following code but i see the same issue:
    http://d.pr/i/dYcg

    Please help me what i am doing wrong here.

    Thank you
    Anunay
  • edited 8:15AM
    The model should have been fuel_pages_model. Also, I just posted a v1.0.2 and you can now try this:
    $CI->fuel->pages->children('our-firm'); // returns an array of page locations $CI->fuel->pages->children('our-firm', TRUE); // returns an array of Fuel_page objects with their keys the page location values
  • edited 8:15AM
    I am afriad that didn't work either. Do I need to created a instance for $CI. I am using these codes inside view file and has no controller but using opt-in-controller. Please suggest.
  • edited January 2014
    I tried the following code inside a view:
    $a = $CI->fuel->pages->children('our-firm',true); print_r($a);

    and the browser crashed! no output no error nothing.

    FYI : I am using fuel 1.0.2 latest version per your suggestion above.
  • edited 8:15AM
    The returned values is an array of objects and each object has a reference to the $CI object. Using print_r on it will cause it to go into an infinite loop. Try something like the following:
    $a = $CI->fuel->pages->children('our-firm',true); foreach($a as $key => $c) { print_r($key); print_r($c->variables()); }
  • edited 8:15AM
    Will check and let you know. thank you:)
Sign In or Register to comment.