Drupal

Customizing Primary Links in Drupal 6

roland's picture

Working with Drupal can be a headache when you are learning the ropes, but it's one of the best CMS out there. I wanted to add ids to the primary links so I can style them with CSS. Here's how I did it:

1. Create or edit your template.php in the your current theme folder (i.e. themes/your_theme/template.php)

2. Edit the function or create the following function in template.php

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  $current_language = $vars['language']->language ;
  foreach ( array('primary_links', 'secondary_links') as $menu_name ) {
    if (! empty($vars[$menu_name])) {
      foreach ( $vars[$menu_name] as $menu_key => $menu_item ) {
        if ( $menu_item['langcode'] != $current_language && ! empty($menu_item['langcode']) ) {
          unset($vars[$menu_name][$menu_key]) ;
        } else {
			$vars[$menu_name][$menu_key]['attributes'] = array('id' => strtolower(str_replace(" ", "_", $vars[$menu_name][$menu_key]['title'])));
		}
      }
    }
  }
}

3. Disable and re-enable your current theme. I disabled it and enabled Garland. You will need to do this only once. After this, any changes, to this function will be made available to you immediately.

This technique works in customizing secondary links too.

4. Now in your page.tpl.php add the following code:

<?php if (isset($primary_links)) :
  print theme('links', $primary_links, array('class' => 'links primary-links'));
endif; ?>

You may have to disable the primary links from the blocks admin page.

Fixing Drupal's Twitter Module

roland's picture

I am moving away from Wordpress to Drupal because it does a bit more than just blogging.

Among many cool tools I decided to install the twitter module. My updates are protected cause I don't feel like wasting my time rejecting bots that are trying to gather personal information. Anyways, because of API changes the module doens't work correctly for protected accounts.

Syndicate content