Hey i was wondering if there was anyway to make the slogan change itself automatically every time the page is refreshed?
Ben McRedmond
Benofsky Park.com

Comments

eaton’s picture

<?php
// $Id$

/**
 * @file
 * Enables the creation of taglines that can be added to the navigation system.
 */

/**
 * Implementation of hook_help().
 */
function tagline_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Enables the creation of multiple site taglines.');
    case 'node/add#tagline':
      return t('Submit a tagline for use on the site\'s banner.');
  }
}

/**
 * Implementation of hook_perm().
 */
function tagline_perm() {
  return array('create taglines');
}

/**
 * Implementation of hook_node_name().
 */
function tagline_node_name($node) {
  return t('tagline');
}

/**
 * Implementation of hook_access().
 */
function tagline_access($op, $node) {
  global $user;

  if ($op == 'create') {
    return user_access('create taglines');
  }

  if ($op == 'update' || $op == 'delete') {
    if ($user->uid == $node->uid) {
      return TRUE;
    }
  }
}

/**
 * Implementation of hook_menu().
 */
function tagline_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $items[] = array('path' => 'node/add/tagline', 'title' => t('tagline'),
      'access' => tagline_access('create', NULL));
  }

  return $items;
}

/**
 * Implementation of hook_form().
 */
function tagline_form(&$node) {
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('tagline', $node));
  }

  $output .= form_textarea(t('The story behind the tagline'), 'body', $node->body, 60, 20, '', NULL, TRUE);
  $output .= filter_form('format', $node->format);

  return $output;
}

function tagline_random() {
  $tagline = variable_get('site_slogan', '');
  
  $result = db_query("SELECT nid, title FROM {node} WHERE type = 'tagline' AND status = '1' ORDER BY RAND() LIMIT 1");

  while ($node = db_fetch_object($result)) {
    $tagline = l($node->title, '/node/' . $node->nid, array('class'=>'tagline'));
  }
  return $tagline;
}
?>

At that point, modify your theme to insert tagline_random() instead of checking the system-wide 'slogan' variable.

This method means that authorized users can also contribute new taglines to the database. On my site, where taglines are often punchlines from group-wide in jokes, we wanted each one to link to an explanation. You can modify the tagline_random() function to return plain text instead of a link, if you'd like.

--
Jeff Eaton | Click Here To Find Out Why Drupal "Sucks"

--
Eaton — Partner at Autogram

Peli-1’s picture

That's nice ... A question from total progrrammin noob (yeah, I'm just a designer): where do you put the code?! In page.tpl.php or somewhere else?!?!??

Davorin
www.em3r10.com

Christefano-oldaccount’s picture

I've been using a page.tpl.php hack for this on some sites, but now we can all use Richard Eriksson's Fenchurch omnibus module.