Hello all,

Thnx for the wonderful module!
I m having troubles to find how and where i have to put the code into template.php
This is the instruction from the module:

4. The page title is ultimately set at the theme level. To let your PHPTemplate
   based theme interact with this module, you need to add some code to the template.php
   file that comes with your theme. If there is no template.php file, you can simply
   use the one included with this download. Here is the code:

function _phptemplate_variables($hook, $vars) {
  $vars = array();
  if ($hook == 'page') {

    // These are the only important lines
    if (module_exists('page_title')) {
      $vars['head_title'] = page_title_page_get_title();
    }

  }
  return $vars;
}

  As you can see from the code comment, there are only three important lines
  of code:

  if (module_exists('page_title')) {
    $vars['head_title'] = page_title_page_get_title();
  }

  These lines need to be added to the 'page' hook of the _phptemplate_variables
  function.

  Alternately, you can call page_title_page_get_title() from page.tpl.php
  directly at the place where the title tag is generated.

This is my template.php:

<?php
/**
 * Sets the body-tag class attribute.
 *
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
 */
/*
function phptemplate_body_class($sidebar_left, $sidebar_right) {
  if ($sidebar_left != '' && $sidebar_right != '') {
    $class = 'sidebars';
  }
  else {
    if ($sidebar_left != '') {
      $class = 'sidebar-left';
    }
    if ($sidebar_right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}
*/

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' ›› ', $breadcrumb) .'</div>';
  }
}

/**
 * Allow themable wrapping of all comments.
 */
/*
function phptemplate_comment_wrapper($content, $type = null) {
  static $node_type;
  if (isset($type)) $node_type = $type;

  if (!$content || $node_type == 'forum') {
    return '<div id="comments">'. $content . '</div>';
  }
  else {
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
  }
}
*/

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      // These next lines add the required stylesheets file and redefine
      // the $css and $styles variables available to your page template
      $vars['css'] = drupal_add_css($vars['directory'] .'/andreas01.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/style.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/print.css', 'theme', 'print');
      $vars['styles'] = drupal_get_css();
	  // Add a custom textarea.js-file to the page
	  //$vars['js'] = drupal_add_js($vars['directory'] . '/js/textarea.js', ' theme', 'header', FALSE, $cache );
      break;

	default:
	  break;
  }
  return $vars;
}

/**
 * Returns the rendered local tasks. The default implementation renders
 * them as tabs.
 *
 * @ingroup themeable
 */
/*
function phptemplate_menu_local_tasks() {
  $output = '';

  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
  }

  return $output;
}
*/

function phptemplate_menu_tree($pid = 1) {
  if ($tree = menu_tree($pid)) {
  switch ($pid) {
    case 1:
      return "\n<ul class=\"avmenu\">\n". $tree ."\n</ul>\n";
/*
	case (variable_get('menu_primary_menu', 0)):
      return "\n$<ul class=\"links primary-links\">\n". $tree ."\n</ul>\n";
	case (variable_get('menu_secondary_menu', 0)):
      return "\n<ul class=\"links secondary=links\">\n". $tree ."\n</ul>\n";
*/
	default:
      return "\n<ul class=\"menu\">\n". $tree ."\n</ul>\n";
	}
  }
}

function phptemplate_menu_item_link($item, $link_item) {
  return l_curr($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}

function l_curr($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
  if ($path == $_GET['q']) {
    if (isset($attributes['class'])) {
      $attributes['class'] .= ' current';
    }
    else {
      $attributes['class'] = 'current';
    }
  }
  return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) .'</a>';
}

It would be wonderful to get this working!

I hope someone can help me, i ve got the feeling it isnt really difficult but too difficult for me :)

Thanks,
Jansmale

Comments

nicholasThompson’s picture

Assigned: stanleyb23 » nicholasThompson
Status: Active » Fixed

Basically, find your _phptemplate_variables function... which is this:

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      // These next lines add the required stylesheets file and redefine
      // the $css and $styles variables available to your page template
      $vars['css'] = drupal_add_css($vars['directory'] .'/andreas01.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/style.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/print.css', 'theme', 'print');
      $vars['styles'] = drupal_get_css();
  // Add a custom textarea.js-file to the page
  //$vars['js'] = drupal_add_js($vars['directory'] . '/js/textarea.js', ' theme', 'header', FALSE, $cache );
      break;

default:
  break;
  }
  return $vars;
}

Now in here, you want to tell it to set the head_title in the $vars array when $hook is 'page' and only if the page_title module exists (last bit stops the site breaking if you disable the module)... This means your function turns into...

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if (module_exists('page_title')) {
        $vars['head_title'] = page_title_page_get_title();
      }
      // These next lines add the required stylesheets file and redefine
      // the $css and $styles variables available to your page template
      $vars['css'] = drupal_add_css($vars['directory'] .'/andreas01.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/style.css', 'theme', 'screen, projection');
      $vars['css'] = drupal_add_css($vars['directory'] .'/print.css', 'theme', 'print');
      $vars['styles'] = drupal_get_css();
  // Add a custom textarea.js-file to the page
  //$vars['js'] = drupal_add_js($vars['directory'] . '/js/textarea.js', ' theme', 'header', FALSE, $cache );
      break;

default:
  break;
  }
  return $vars;
}

This should do the trick! Post back if you have any further issues.

stanleyb23’s picture

Thank you!
I ve tried it but the strange thing is that my search function stopped working and my login is causing problems. Very strange. Do u have an idea how this script causes trouble for my log in and search node?

Thanks a lot

mikew_is’s picture

Hi I am totally new to drupal and am not a programmer and do not know php at all. I followed your instructions and "walla" it works like a dream - THANKS!!! I am still not sure what implecations this has on my search (it has not been working since I started creating my site :-) )

nicholasThompson’s picture

I have no idea why this would break search and login - it certainly doesn't on my site and there are no other reports of this happening to anyone else which suggests to me that your problem is not with Page Title but something else.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

mikew_is’s picture

I was just going through my posts, I am still a newbie and loving drupal, but now I know why my search was never working - i needed to run cron.php. For those that are as new and green as me, what you need to do in order to get your search working is write the following: http://yoursite.com/cron.php

nicholasThompson’s picture

Alterntiviley...
http://drupal.org/project/poormanscron

Cron should be run regularly. If you cannot schedule your server to execute cron, you might need a module to do it for you.

Cron will also do some other stuff like cleanup the watchdog table which can grow to be HUGE if not maintained.