Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hey there-

How could I make this situation possible:

Page A (list three root folders)
FolderA, FolderB, FolderC

Then, when clicking on one of these folders - you are taking to a page containing only THAT root folders sub-folders

Page B (The children of only THAT root)
FolderA --> SubA1, SubA2, SubA3, etc.

My current code is the following on Page A:

Code: Select all
<cms:folders masterpage='addproduct.php' orderby='publish_date' order='asc'>
   <a href="<cms:show k_folder_link />" class="product_category ol inner_ol hover">
      <img src="<cms:show k_folder_image />">
      <div class="category_text">
         <h1><cms:show k_folder_title /></h1>
      </div>
   </a>
</cms:folders>


But at the moment this code lists all folders AND subfolders, I only want it to list the three ROOT folders - linked to a page of that ROOTs sub-folders, and then eventually, that sub-folders pages.
Hi,
Assuming that the code is running in folder-view, the following modification of your code should handle all that.
Code: Select all
<cms:if k_is_folder>
 
    <cms:folders masterpage='addproduct.php' order='asc' depth='1' childof=k_folder_name>
       <a href="<cms:show k_folder_link />" class="product_category ol inner_ol hover">
          <img src="<cms:show k_folder_image />">
          <div class="category_text">
             <h1><cms:show k_folder_title /></h1>
          </div>
       </a>
    </cms:folders>

    <cms:pages masterpage='addproduct.php' folder=k_folder_name include_subfolders='0'>
        <h1><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h1>
    </cms:pages>
   
</cms:if>

To explain - setting depth='1' shows only folders one level deep.
childof=k_folder_name makes use of the k_folder_name variable made available in a folder-view indicating the folder being visited. This constrains the listing to only the children of the folder.
Finally, the cms:pages tag also uses k_folder_name to bring in immediate pages of the folder.

Hope this helps.
Is there a way to check depth of a folder?

I have this code now:

Code: Select all
<cms:if k_is_folder>
      
      <!-- block#1 - CHECK TO SEE IF THIS FOLDER IS AT DEPTH 1, DISPLAY ONLY MORE SUB-FOLDERS

      <h1 class='page'>sub</h1>
      <hr>
      <cms:folders masterpage='addproduct.php' order='asc' depth='1' childof=k_folder_name>
         <a href="<cms:show k_folder_link />" class="product_category ol inner_ol hover">
           <img src="<cms:show k_folder_image />">
           <div class="category_text">
             <h1><cms:show k_folder_title /></h1>
           </div>
         </a>
      </cms:folders>
      
               <!-- block#2 - OTHERWISE, THIS FOLDER MUST BE AT DEPTH 2, ONLY DISPLAY PAGES AT THIS LEVEL
      
      <h1 class='page'>pages</h1>
      <hr>
      <cms:pages masterpage="addproduct.php" folder=k_folder_name >
         <a class="product_category_list ol inner_ol hover" href="<cms:show k_page_link />">
            <img src="<cms:show product_image />">
            <div class="category_text">
               <h5><cms:show k_page_title /></h5>
            </div>
         </a>
      </cms:pages>
   </cms:if>


Without the if or else statements I am looking for, it works correctly - BUT I want to have block #1 on one page, only showing more sub-folders, then upon clicking one, block #2 showing only page links
There is no explicit variable available that shows the folder's level.
There could be workarounds to deducing the level, however for your particular requirement the following should be sufficient -

A variable named k_folder_parentid is available in folder-view showing the id of the current folder's parent. Top level folders obviously have no parents so while visiting them this variable is always set to '-1'.
I think, we can use this info to code your logic.

The code would become
Code: Select all
<cms:if k_folder_parentid='-1'>
    <!--  Top level folder. Show child folders -->
<cms:else/>
    <!-- Sub folder. Show pages. -->
</cms:if>

Does this help?
That is exactly what I was looking for, thank you!
You are welcome :)
6 posts Page 1 of 1