Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I have (again) got into difficulties trying to use folders and subfolders in conjunction with site navigation. I have tried for a long time to get this sorted out and have referenced previous postings here on the forum but have only got into a deeper mess as time has gone on! I don't really have any sensible code to post. If I describe what I am trying to achieve perhaps some kind person could help me out!

There are categories of art with sub-categories e.g. paintings with sub-categories of watercolours and publications. Paintings = a parent folder and watercolours and publications = sub-folders of Paintings.

So something like this:

paintings
- watercolours
- publications
sculpture
- life
- abstract
craft
- ceramics
- jewellery
installations
projects
- film
- community

There may be a folder without children e.g. installations.

In the main navigation there will be a link called WORK which has a dropdown menu with the parent folders listed:

navigation.jpg
navigation.jpg (15.09 KiB) Viewed 1153 times

i.e. click on WORK and a dropdown menu shows:

PAINTINGS
SCULPTURE
CRAFT
INSTALLATIONS
PROJECTS

Code: Select all
<cms:folders masterpage='work.php' orderby='weight' hierarchical='1' depth='1'>
  <li><a href="<cms:show k_folder_link />"><cms:show k_folder_title /></a></li>
</cms:folders>



Click on PAINTINGS from within this dropdown menu and the page should show the heading 'PAINTINGS' along with sub-navigation links of the child folders of PAINTINGS - as shown in the mockup. The listing by default would show the contents of the first child folder i.e. WATERCOLOURS. Click on PUBLICATIONS and the contents of that child folder would be displayed.

Select INSTALLATIONS from the WORK dropdown menu and the contents of that parent folder (no children) will be displayed.

I cannot fathom how to achieve this - am ready to give up and think of some other way of doing this, but folders seems like a good way to structure the site ... help please?!
Hi,

There could be several ways of handling this. Please try the one given below -
Code: Select all
<cms:if k_is_folder>

    <!-- if a root folder is being visited and it has some children below it.. -->
    <cms:if k_folder_parentid eq '-1' && k_folder_immediate_children>

        <!-- .. redirect to the first child below it -->
        <cms:folders childof=k_folder_name>
            <cms:redirect k_folder_link />
        </cms:folders>
    </cms:if>
   
    <!-- at this point, either we are in a root folder with no children or a child itself -->
    <cms:set cur_folder=k_folder_name />
   
    <!-- get the top most folder -->
    <cms:parentfolders folder=k_folder_name >
        <cms:if k_folder_parentid='-1' ><!-- in case of a root folder, this will be the folder itself -->
            <h1><cms:show k_folder_title /></h1>
           
            <!-- sub-nav: get the children of the top most folder (this will include the folder being visited) -->
            <cms:folders childof=k_folder_name ><!-- in case of a root folder, this loop will not execute as it has no child folders -->
                <a href="<cms:show k_folder_link />" class="<cms:if k_folder_name eq cur_folder>current</cms:if>">
                    <cms:show k_folder_title /> <cms:if k_folder_name eq cur_folder>*</cms:if>
                </a><br>
            </cms:folders>
        </cms:if>
    </cms:parentfolders>   
   
    <!-- the current folder -->
    <h3>This is a folder-view of <cms:show k_folder_title /></h3>
    ...
</cms:if>

I have tried to explain the code using comments.
Please let me know if this helps.
thank you SO much @kk - I am very grateful indeed for your help in this. I actually don't think I was ever going to get that working ... it seems complex so I really appreciate the comments in your code as well, I'll try to understand how you've done it. I think this is something that'll be really useful for other sites I may do ... again thanks a million for all the time you give to helping on the forum!
3 posts Page 1 of 1
cron