Remove Title

Joined: 02/08/2009
Juice: 14

I'm sure there are a few ways to do this, but here is how I would go about it. You can also refer to this page:

http://drupal.org/node/138910

If you go to your page.tpl.php (in your currently selected themes directory) and find the following code:

    <div id="middle-content">
      <div class="content-padding">
          <?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
          <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
          <?php if ($tabs): print $tabs .'</div>'; endif; ?>

          <?php if (isset($tabs2)): print $tabs2; endif; ?>

          <?php if ($help): print $help; endif; ?>
          <?php if ($messages): print $messages; endif; ?>
          <?php print $content ?>
          <span class="clear"></span>
          <?php print $feed_icons ?>

          <div style="clear:both;"></div>
      </div>
    </div>

The

<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>

is the line that prints out the title of your node, which you have to enter when creating the node.

Now you have two choices to stop that title from displaying. The first is to give the h2 tag (that wraps around the title) a specific class or ID and then use CSS on that class or id and set it to display: none.

Of course this may not be the most efficient way as we are printing the title and then just hiding it.

What you could do is add to the if argument in front of the print title statement, so that it checks to see if the current node is of a type that you don't want to print a title for. Looking at the image your provided you probably want to hide the title on all nodes of the type product?

How you can do this depends on whether you are using pathauto or not. I am going to assume you are. What you want to do is look at your page url and decide whether this page contains a node of type products. So if your url is:

http://www.mysite.com/products/coffeepress

We will check and see if arg(0), which is the Drupal constant/variable for the first argument of the url, is equal to 'products'. Now, I believe, if you do this and you are using pathauto this will not return the argument as you see it in the url, instead it will return something like 'node'. If so you can add the following code to the top of your page.tpl.php (courtesy of DrupalSN):

<?php
    $path
= drupal_get_path_alias($_GET['q']); //get alias of URL
   
$path = explode('/', $path); //break path into an array
    //user print_r($path); to see what the $path array looks like
?>

This takes the current url as it is displayed and makes the values in to an array. So now instead of checking the contents of arg(0) we check the contents of $path[0].

So now your code that prints the $title should be written like this:

<?php if ($title && $path[0]!='products'): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>

So now we are checking the first argument of the current url. If it is equal to products we will not print the title but if it is not the title will print.

I have attached a sample page.tpl.php so you can see what it looks like.

I hope that helps. Again I am no expert, so if anyone has any other suggestions they are welcome.

Good Luck,
Mat

AttachmentSize
page.tpl_.php_.txt 4.4 KB
Nifty Products Tutorial Part 1 By: mykz- (132 replies) Wed, 03/19/2008 - 19:04