Hi,

Does anyone know how I can automagically have the system show all secondary links in a block?

Thanks.

Comments

nevets’s picture

If your seconday links are different than your primary links there will be a block you can enable.

Littlebob’s picture

My secondary links are: My Account, My Inbox (I have the privatemsg module installed), My Subscriptions, Recent posts, administer (when logged in as admin) and Log out. Where is the block that I can enable?

nevets’s picture

Have you made a menu from those links?

Under "Administer" > "Site building" > "Menus"

You would need to add a new menu with these links

Under "Administer" > "Site building" > "Blocks"

Enable the new block for the menu

marcvangend’s picture

Hi,

I happen to be working on that as well. I have the primary and secondary links set to the same menu, so when a primary menu item is activated, the child menu items will show up as secondary links. Right now the secondary links are rendered in page.tpl.php, but I want to put them in a block.

The php code in my template (based on Zen) to produce the secondary links is:

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

I just put that code in a new block and published it, but that didn't work. Next I tried adding <?php echo "sl = $secondary_links";?> and <?php print_r($secondary_links);?> to the block, but the block remained empty. Obviously, the $secondary_links variable isn't available here. If anyone knows how to solve this, please tell us. If I figure it out myself, I'll let you know.

nevets’s picture

Add this line before your snippet

<?php $secondary_links = menu_secondary_links(); ?>
marcvangend’s picture

I found it! api.drupal.org to the rescue!
On http://api.drupal.org/api/function/phptemplate_page/5 I found the function which prepares the variables for page.tpl.php. As it turns out, there is a simple function which returns the $secondary_links array. So, you can just start your secondary links block with calling this function. My block code now looks like this:

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

It works like a charm (Drupal 5.7).

[edit]LOL, while I was typing my solution, it was also given by nevets... Thanks for helping, I'm glad we agree :-)[/edit]

darumaki’s picture

How to set this up in drupal 6 ?

marcvangend’s picture

I don't know, do you expect me to go and figure it out and then present the results to you on a silver tray?

Come on, you can do better than this. Have you actually tried to just use the D5 code? Tell us what you tried so far, what the output was, if you got any error messages, which relevant documentation you have found, what you think might be the problem...

darumaki’s picture

um, well, maybe not a silver tray but platinum, you bet and use gold for the trim :)

I did try the code and it didn't work ? I wouldn't have posted, if it did (knocking on wood), I no longer need it, I did away with the page coded menu and done all through the menu blocks.

marcvangend’s picture

OK, good for you that you found another solution, my point is, it's hard to help you if you provide so little information.

KrisBulman’s picture

worked for me using the clean theme in drupal 6.6 by throwing this snippet in a block

<?php 
$secondary_links = menu_secondary_links();
if ($secondary_links): ?>
    <div id="navigation">
         <?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?>
    </div>
<?php endif ?>
primsi’s picture

Works great for me also. There is just another thing I would like to do: get the 'secondary links' 'father' as a title:

 <?php if($secondary_links): ?>
   <h2>i_need_title_here</h2>
   <?php print theme('links', $secondary_links); ?>
 <?php endif; ?>

Any ideas? I have tried using menu_get_active_trail(), but it doesn't give me the 'father'. It returns an array like this:

[0] - Home
[1] - Node_i_am_currently_viewing

but my primary links structure is:

- A
- B (I try to print out this as h2)
-- b1 (I am here)
-- b2
- C

Thx

primsi’s picture

Not nice, but works for now:

<h2>
<?php
  foreach ($primary_links as $key => $link) {
    if (stristr($key, 'active-trail')) { print $link['title'];}  
  }
?>
</h2>
B0N35’s picture

FINALLY THANKS ALOT