0

Is there a way to dynamically create a main navigation (e.g. every template group appears in the main nav)? I want to set up EE so that when the client/user adds pages, they'll appear as either a new item in the navigation, or an item under the navigation, etc.

I'm trying to avoid having the client/user actually make edits in the templates.

2
  • Can you clearly describe the structure of nav or sub-nav (if there). it's doable with with the query Commented Feb 2, 2013 at 14:47
  • 1
    I realized I required more data, right after I was finishing my response. My question is, surely you don't want every page to appear in the navigation, unless the site will be very small. So what constitutes a navigation item vs a regular post. Or are you working with Pages and Structure or Pages without Structure? Commented Feb 2, 2013 at 15:11

2 Answers 2

1

With the top nav it's a little trickier, but with the sub nav within a given section, I do that all the time. I tend to think of top nav as being fixed, not only programmatically, but from a business perspective, your top nav is a representation of what you do, so planned accordingly, it may not change often (obviously, this depends on what you do). The pages within a given section though, I tend to approach with entries creating pages within the given section, and therefore i can choose whether they display in the top nav. I can make it to that ever page appears as a dropdown item within a given channel's main nav item, or i can even make that optional by adding an admin/owner checkbox or something like that to indicate whether the item should os shouldn't be included in the top nav. I've also done things like an alternate title field for use in the dropdown nav (since the "real" title may be a bit long so you might want it represented differently in the navigation, for example).

Taking that approach requires a bit of planning, but I do it often and it works just fine. As nonprofit_tech indicated, having your client creating templates groups, etc. means more work for them than the simple creation of entries, so it may not be ideal.

0

This is probably easiest, if you matched template_group names to channels or sections of the site. You would basically create a custom query, that pull just not excluded channels. This assumes, there are some channels, where data is combined into a different section, or that are used for utility purposes, like sectional_text or transactions, etc.

SELECT channel_title, channel_description, channel_name, channel_url, total_entries 
FROM exp_channels 
WHERE channel_id 
NOT IN ('15','14','13','9','2','17','4') 
ORDER BY FIELD(channel_name,'item2','item5','item4','item1');

You can also custom order them as needed. You don't need to pull channel_description and other options if they won't be used.

You'd, of course still need the run the subqueries for generation, the page listings under the main section navigation. But that should get you started. The primary point is to use MySQL's NOT IN so you can list out the excluded items, since they are far less likely to change.

Though it occurs to me, if you don't have clients creating new template groups, why would you have them creating new channels. So this response, probably isn't exactly what you are looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.