Currently Browsing: web programming

Graphing wind speed and direction using RRDtool

Using XML feeds from wunderground.com you can easily graph wind speed and direction with RRDtool and then format the output with PHP for iPhone. Below is a screenshot of a site I created at http://redigital.org/wind/ which tracks various weather stations in Santa Barbara, CA and Sedona, AZ.

Most of my source code is available at http://redigital.org/wp/?p=143 but I can post anything that’s missing.


Drupal: Sorting by last name given the Title in a link field

preg_match('~([^\s]+)(?:,.*)?$~',$node->field_faculty_link[0]['title'], $match);
$node_field[0]['value'] = $match[0];

Extracting First and Last name from a single field in a drupal content-type

It is possible to extract the first or last name from a single field in a drupal content-type using the computed_field module. Here were my steps, taken from the drupal structure guide :

  1. install computed_field and dependencies
  2. % drush dl computed_field
    Project computed_field (6.x-1.0-beta3) downloaded to      [success]
    /var/www/drupal6/sites/all/modules/computed_field.
    % drush en computed_field
    The following projects will be enabled: computed_field
    Do you really want to continue? (y/n): y
    computed_field was enabled successfully.                  [ok]
  3. edit your content type
  4. add a new ‘Computed’ field
  5. under Global settings, make certain the ‘Computed Field’ is in plain-text mode
  6. for last name
    • // compute last name
      preg_match('~([^\s]+)(?:,.*)?$~',$node->title, $match);
      $node_field[0]['value'] = $match[0];
    • for first name:
      // compute first name
      $node_field[0]['value'] = \
                      substr($node->title, 0, strrpos($node->title, " "));
  7. change data-type to “varchar”
  8. enable/check “Sortable”
  9. Save content-type
  10. Edit your view
  11. Add a ‘Sort Criteria’
  12. Use Content: Computed Last Name (field_computed_lastname)
  13. Click ‘Update’ and then save your view
  14. Navigate to the page where your listing is to see the new sorted version

No-Click Hover Links using Drupal & Nice Menus

I encountered a problem while viewing  a Drupal site with Nice Menus on an Android whereby you could not get to the submenu when clicking on the parent links. On an iPhone a single-tap is taken

1) set URL for parent links that you don’t want to take you anywhere to http://fake.link

2) add the following code to your template.php (at bottom is fine) – note prefix of function name is the template name ${template_name}_menu_item_link()

/* 2010-06-24 randall <>
 taken from http://drupal.org/node/143322#comment-1166563

 */

function zeropoint_menu_item_link($link) {
 if (empty($link['localized_options'])) {
 $link['localized_options'] = array();
 }

 if (!$link['page_callback'] && strpos( $link['href'], 'fake.link')) {
 return '<a href="#">'. $link['title'] .'</a>';
 }
 else {
 return l($link['title'], $link['href'], $link['localized_options']);
 }
}

3) check your navigation bar


Zen Theme and Nice Menus – CSS Block Padding Issue

this fix was originally found here (http://www.1drupal.com/content/zen-theme-and-nice-menus-block-padding-issue) but i’m reposting in case that site goes away…

when using a customized Drupal Zen Theme, and Nice Menus instead of the standard Primary Navigation Menu extra padding can appear above or below the navigation bar. The Nice Menu is a block and inherits the default margin from Zen’s CSS.

.block /* Block wrapper */
{
margin-bottom: 1em;
}
you can change “1em” to “0” or delete that statement and add:
#block-nice_menus-1 {
margin-bottom: 0;
}
“-1” is for nice menu 1 (in this case, the primary menu).

« Previous Entries Next Entries »

Powered by WordPress | Designed by Elegant Themes