ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic Navigation Link Dilemma

September 05, 2012 5:09am

Subscribe [2]
  • #1 / Sep 05, 2012 5:09am

    I need to build a dynamic nested navigation link. However we are stuck. So here is the issue.

    PROJECTS                        SERVICES 
       All Projects (category)         All Services
       Design (category)               Service
           Design 1 (page)                  Design 1
           Design 2 (page)                  Design 2
           Design 3 (page)                  Design 3
       Construction  (category)        Construction
           Construction 1  (page)          Construction 1
           Construction 2  (page)          Construction 2
           Construction 3  (page)          Construction 3


    The top level navigation (PROJECTS and SERVICES) are static.  But each sub-level navigation such as (all projects, design, construction) are categories. Under each of these sub-categories, there are multiple pages that are generated using EE templates.

    My dilemma is how can this navigation be created so that it dynamic. By dynamic, I mean when the admin adds an additional sub-category, inside “projects” main category then they to be displayed on the menu bar. Similarly, when the admin creates a new page, then that page link need to display within appropriate category. I hope that makes sense. Can anybody guide me little bit to start off. Your help is greatly appreciated.

  • #2 / Sep 05, 2012 6:56am

    Enviromed

    375 posts

    Welcome to ee!  You might consider the very popular:

    http://devot-ee.com/add-ons/gwcode-catmenu

    Good luck!

  • #3 / Sep 06, 2012 4:29pm

    Kevin Smith

    4784 posts

    Thanks for the tip, Enviromed!

    transwebsolutions, does that help do what you need it to do?

  • #4 / Sep 07, 2012 7:37am

    i was actually able to achieve it using php but this one is nicer.

  • #5 / Sep 10, 2012 8:23am

    i check out the addon, but it doesn’t serve my purpose. the menu that i need to generate is the mix of category and entries. if it were all category, then it would have served it.

    anyway, i wrote this code but failing for one reason.
    in nested loops the variables from the parent loops are still persistent and overwriting the variable in the child loop.

    here is the snippet of my code.

    {exp:channel:categories category_group="{services_group_id}" style="linear"}
      
      <li>
       <a href="#aa">{category_name} - {count}-{total_results}</a>
       {if count == 1}
                            </ul> 
                            {/if}
       
       
       {exp:channel:entries channel="services" category="{category_id}"}
        
    
        <li><a href="#">{title}-{count}-{total_results}</a></li>
    
        
       {/exp:channel:entries}
       {if count == total_results}
                            </ul> 
                            {/if}
           
       
      </li>
     {/exp:channel:categories}

    in this example i want to count the number of entries in the child loop but the {count} variable still holds the value assigned by the parent loop. any way to solve this issue

  • #6 / Sep 10, 2012 2:12pm

    Dan Decker

    7338 posts

    Hi transwebsolutions,

    You nailed the problem:

    in nested loops the variables from the parent loops are still persistent and overwriting the variable in the child loop.

    In most cases it is cumbersome at best to nest modules - in this case channel categories and channel entries. You are halfway there though. We just need to move your entries pair to an embed:

    {exp:channel:categories category_group="{services_group_id}" style="linear"}
      
      <li>
       <a href="#aa">{category_name} - {count}-{total_results}</a>
       {if count == 1}
                            </ul> 
                            {/if}
       
       
       {embed='template-group/template' my_category='{category_id}'}
       {if count == total_results}
                            </ul> 
                            {/if}
           
       
      </li>
     {/exp:channel:categories}

    And your embed template would have this:

    {exp:channel:entries channel="services" category="{embed:my_category}"}
        
    
        <li><a href="#">{title}-{count}-{total_results}</a></li>
    
        
       {/exp:channel:entries}

    That should solve your overwrite problems!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases