Hi guys!

I'm trying to hide titles of my nodes from being displayed in view mode.
Recently I was advised to use auto_nodetitle. It really helps with creating of automatic titles and hiding the Title field in Edit form (when user submits new content). But when users view the site titles of nodes are still visible.

Does anybody have some ideas ?

Comments

retswerb’s picture

I'm in need of this too, frustrated as it seems like this ought to be one of those really entry-level things that should be considered necessary, basic functionality.

Here are some things I've tried:
http://drupal.org/node/399112
http://drupal.org/node/138910
and there's a comment down the page on http://drupal.org/node/221854 that gives code to let you hide the display of node titles by adding an underscore at the beginning of the title name.

But none of them have done anything, I'm still left with titles displaying on all my pages, even the front page. None of these 'fixes' have had any effect. I'm running Drupal 6.6 with the litejazz theme. Anybody got any advice?

retswerb’s picture

Ok, got it. The above-mentioned fix that is referred to in a comment on http://drupal.org/node/221854 finally worked, it was the last thing that I had tried and I had forgotten to run cron after adding the code to my page.tpl.php.

Hunt through that file until you find the title listing and edit it to look like this (taken completely from nstrassner's comment on the above node):

<?php if(substr($title,0,1) != "_") { ?> 
<h2 class="title">
<a href="<?php print $node_url?>">
<?php print $title?></a></h2> <?php 
    } ?>

Save your change and run cron.

Then anytime you want the title not to display, begin the title name with an underscore (such as _qwerty) and that title will not be displayed.

mrtoner’s picture

This works great, except that the page title is also used as a menu's title attribute in primary and secondary links:

<ul class="links primary-links"><li class="menu-249 first last"><a href="/home" title="_Home">Home</a></li></ul>

Any suggestions for removing the "_" from the title attribute?

mrtoner’s picture

Okay, here's what I've come up with so far:

hide_node_title.info

; $Id$
name = Hide Node Title
description = "Provides option to suppress node titles on a per node basis."
core = 6.x
package = Other

hide_node_title.install

// $Id

/**
 * @file
 * The install file for Hide Node Title allows the module to install (and uninstall) itself. This is required as this module uses its own table.
 */

/**
 * Implementation of hook_install().
 */
function hide_node_title_install() {
  drupal_install_schema('hide_node_title');
}


function hide_node_title_schema() {
  $schema['hide_node_title'] = array(
    'fields' => array(
      'nid'        => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'hide_title' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
    ),
    'primary key' => array('nid'),
  );

  return $schema;
}


/**
 * Implementation of hook_uninstall().
 */
function hide_node_title_uninstall() {
  drupal_uninstall_schema('hide_node_title');
}

hide_node_title.module

/**
 * Implementation of hook_perm().
 */
function hide_node_title_perm() {
  return array('hide node title');
}

/**
 * Implementation of hook_form_alter().
 */
function hide_node_title_form_alter(&$form, $form_state, $form_id) {
  // If we don't have permission to hide the title then we need to abort this alter now!
  if (!user_access('hide node title')) return;

  // Only alter node forms.
  if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {
    $form['hide_node_title'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide title'),
      '#description' => t('Optionally hide the title when this content is displayed.'),
      '#default_value' => $form['#node']->hide_node_title,
      '#options' => t('Hide'),
      '#weight' => -4,
    );
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function hide_node_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'update':
      if (user_access('hide node title')) {
        db_query("DELETE FROM {hide_node_title} WHERE nid = %d", $node->nid);
      }
      // Fall through to insert is intentional!
    case 'insert':
      if (isset($node->hide_node_title) && $node->hide_node_title == 1 && user_access('hide node title')) {
        db_query("INSERT INTO {hide_node_title} VALUES (%d, %d)", $node->nid, $node->hide_node_title);
      }
      break;

    case 'delete':
      db_query('DELETE FROM {hide_node_title} WHERE nid = %d', $node->nid);
      break;

    case 'load':
      return array('hide_node_title' => hide_node_title_hide_title($node->nid));
    case 'view':
      drupal_set_title(($node->hide_node_title == 1) ? '' : $node->title);
  }
}

function hide_node_title_hide_title($nid) {
  return db_result(db_query('SELECT hide_title FROM {hide_node_title} WHERE nid = %d', $nid));
}

/**
 * Implementation of hook_preprocess_page().
 */
function hide_node_title_preprocess_page(&$vars) {
  $vars['title'] = ($vars['hide_node_title'] == 1) ? '' : $vars['title'];
}

hide_node_title_preprocess_page() isn't working and I don't know why, so I've resorted to using drupal_set_title() in hook_nodeapi. That means that the node title is removed from the <title> tag, but I'm using Page Title module and can put that back. Comments are welcome to improve this.

In the end, this provides an easy way to hide the node title without affecting other uses of the data.

summit’s picture

Subscribing,
Still needing it on views-level and not on every node level.
I want the node-titles on one particular view be hidden. I use them to arrange the view, so may be some css will do the trick.
Did anyone succeed in hiding the node title without altering it, on views level?

Thanks a lot in advance for your reply!
greetings,
Martijn

Yuki’s picture

Subscribing,

sonlinemedia’s picture

subscribing

duckzland’s picture

Try to use drupal_set_title('') I should remove the title

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

arnaudfischer’s picture

Subscribing

doublejosh’s picture

I've used a theme based technique in the past, to allow node level control.

1. Create a Hide Title field via CCK

2. Do a quick test in your theme page.tpl.php

<?php
if($title && $node->field_show_title[0]['value']!=1) { $titleTest=true; }
else{ $titleTest=false; }
?>

3. Print the title

<?php if($titleTest){ ?>
 <h1 class="title"><?php print $title; ?></h1>
<?php } ?>

I would NOT recommend this if you want to control this by content type.

aac’s picture

Subscribing!!

---~~~***~~~---
aac

reetle44’s picture

Finally! I'm ecstatic!

zubo01’s picture

says it all...

thank you...

george

charlie-s’s picture

I would still like to know how to set this in the render_array for a $view_mode. Perhaps that's not possible, though.

laghalt’s picture

Posted on wrong thread.

jiangleo’s picture

That is my way to achieve the target:
1. Under FORMAT choose "show: Fields" instead of " Content"
2. Under FIELDS: add the fields you want to show in the view, such as Content: Body, Content: Image, etc.
3. Remove Content: Title if it is in the list by default.

Shahar’s picture

jiangleo, Great solution!
No code involved! classic!
Thanks for sharing!!

Minotaur Wrangler’s picture

I'm late to the party but this little guide totally save my butt tonight. The selective use of fields in the view saved this cowboy's bacon. Thanks a bajillion!

Minotaur Wrangler’s picture

...saying that on/off functionality for node titles and displaying them needs to be a part of Drupal. Sometimes you need a node with no visible title. Sometimes you don't want to go spelunking into code to do that.

thomasmurphy’s picture

This can be done with display suite.