Jump to content

Building a tree layout


felic
 Share

Recommended Posts

Hi everyone!

I have parent page (and template) dates with numerous child pages for single event dates. Beside the content related fields each child page contains two fields which are added (for now) just for sorting purposes (item_sorting_monthitem_sorting_year). Getting those child pages and output them in a straight foreach loop is simple:

$current_date = date("d.m.Y");
$items = $page->children("item_date>=$current_date, sort=item_sorting_year, sort=item_sorting_month");

foreach($items as $item) { .. }

This gives me a well sorted flat output like this:

- item

- item

But what i like to achieve (and doesn't get it right) is this:

- Year

-- Month

--- item

-- Month

--- item

- Year

-- Month

--- item

-- Month

--- item

Additionally i like to establish a anchor link navigation to all available month, e.g. Feb.2016, Jul.2016, Jan.2017 a.s.o. because the list might be a large one.

I spent more than a day with several trail/error (separate $page->find(...), nested foreach loops etc.) at least. But all leads to nothing :-/

Maybe some of you have some hints where to look at, e.g. how to achieve this. I hope my description is precise enough. Otherwise, please don't hesitate to ask.

Cheers and thx in advance

Link to comment
Share on other sites

I guess you are trying to build something like this. It is an example blog profile for PW built by ryan. Here is the source code for that page - a place to copy-and-paste from or get inspired with. If it does not help, feel free to write back.

By the way, you don't need those extra fields just for sorting purpose as you will see in the code provided. One date field holds all the data needed to make that tree.

Edited by Ivan Gretsky
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...