views:

36

answers:

2

How do you get children of primary links to output in the HTML? Only my parent-level primary links are generating LI's.

I have a very very simple two-level primary links menu. There are 5 pages on the site: three parents, and the third parent has two children. In the administrative menu settings I have the parents' and childen's 'expanded' checkbox checked.

I have tried adding all kinds of functions from stackoverflow (including http://stackoverflow.com/questions/2807397/drupal-6-printing-unadulterated-primary-links-and-all-children) and drupal and elsewhere to template.php to get the children to output... nothing!

How do you make primary links expanded?? This seems like such a stupid question. Why wouldn't checking 'expand' checkboxes print the children?

A: 

How primary links display is dependent on your theme. Without knowing more about your theme and how it implements primary links, it'd be impossible to say for sure why your primary links aren't expanding.

One thing you could check is the menu settings; in many themes, the second level is a separate menu called Secondary links. You can change this functionality by going to http://example.com/admin/build/menu/settings and setting Source for the secondary links to Primary links: this will display the second level of the primary links menu instead of the (likely empty) secondary links menu.

Mark Trapp
It is a custom theme I am developing. Originally I was using just: <?php if ($primary_links): ?> <div id="nav"> <?php print theme('links', $primary_links); ?> <?php endif; ?>because this was what was suggested in the Drupal documentation. Then I started messing around and borrowing code from posts with the same issue and nothing worked.As far as menu settings go, I don't quite follow you: I thought secondary links was a separate menu entirely? The drupal documentation is very confusing and all over the place.
Sarah Jean
[`theme_links()`](http://api.drupal.org/api/function/theme_links/6) only prints the first level of the the menu. How most themes handle two level primary menus is by also printing `theme('links', $secondary_links)` right below `theme('links', $primary_links)`. Depending on the settings I mentioned in my answer, `theme('links', $secondary_links)` will display either a separate menu or the second level of primary links. You can see how it's done in the Garland theme in [`page.tpl.php`](http://api.drupal.org/api/drupal/themes--garland--page.tpl.php/6/source).
Mark Trapp
Since this sounds like it's your first foray into Drupal theming, I recommend looking at how a couple starter themes work before making your own from scratch: [Zen](http://drupal.org/project/zen) is a good place to start.
Mark Trapp
Yeah I had used Zen previously but didn't really understand it so I wanted to do it from scratch so that I'd understand it better. Apparently that wasn't the best approach. I'll take a closer look at that code and try working woth $secondary_links. Thanks!
Sarah Jean
I'm still not grasping this. I've set the source of secondary links to primary links, I've set all primary menu links to be expanded by default, and I'm printing both $primary_links and $secondary_links in my theme. I'm still only seeing the first level links output to the HTML. Can you point me to any sources that might explain the way menus work in more depth? I'm not seeing any difference between the way my template has set up the menus and the way Zen and Garland have. I don't see any extra functions in template.php for either theme that override the drupal behavior for these menus either.
Sarah Jean
A: 

I wasn't able to get primary links to print their children when using theme('links', $primary_links) in page.tpl.php regardless of configuration settings.

Instead, after hours of searching, I found this page on drupal.org which mentions that primary links will output differently depending on whether they're being used as links in a theme or as a block:

http://drupal.org/node/187932

It's a discussion about how primary links' 'expanded' option may appear as 'not working' when they are being used as a theme option instead of as a block. When used as a block, primary links will show the full hierarchy of the list you set up, including children. When used in the theme, unless you overwrite the default settings for how primary links display for your theme, it will only list the top-level primary links. This is what Mark mentioned as the default behavior above, and what I was experiencing.

To solve my issue, I simply took the code to print the menus out of the page template entirely, and then assigned primary links to the region in my template where the code was before.

so instead of:

<div id="nav">          
     <?php if ($primary_links): ?>
        <div id="primary">
          <?php print theme('links', $primary_links); ?>
        </div> 
      <?php endif; ?>

      <?php if ($secondary_links): ?>
        <div id="secondary">
          <?php print theme('links', $secondary_links); ?>
        </div> 
      <?php endif; ?>
</div>

I now have:

  <div id="nav">
  <?php if ($navigation): ?>
    <?php print $navigation ?>
  <?php endif ?>
 </div>

AND specified a region in my .info file for 'navigation', AND went to the block settings and assigned 'primary links' to my new navigation region.

To get rid of extraneous code outputting into my new navigation region, I also created a new block template for this region that just outputs the content of the block without any additional wrapping divs or heading tags. I ended up with a navigation unordered list that is pretty tidy, and I hope anyone else who is new to drupal and struggles with this issue finds my personal work-around helpful.

Sarah Jean

related questions