Community & Support

Creating a Node without a title or a default title

Is there a way to create a node without a title, or to use a default title the user doesn't enter? I'm working on a quotations module and the quotation doesn't have a title just the actual quotation and the author. Is there a way to not have the title text box show on the submit quote screen? Maybe use a hidden text field that has a set value like "quotation" in it?

Or is there a better way to do this then trying to make the quotes into a node?

Thanks,
--James

Comments

not currently possible

node.module adds the title field and module authors may not currently override that. please submit a feature request.

No title at nodes...

If i'm correct, this feature is submitted several times on the devel-list.. (Please correct me if i'm wrong)
I thought Al made a patch for this, but also not sure about this...

it's easy...

function _MODULE_NAME_auto_title($title,$vid) {
db_query("UPDATE {node} SET title = '%s' WHERE vid = %d",$title, $vid);
db_query("UPDATE {node_revisions} SET title = '%s' WHERE vid = %d",$title, $vid);
}

then,

function CUSTOM_NODE_insert($node) {
$title = 'hahah #'.$node->nid; //your custom title;
_MODULE_NAME_auto_title($title, $node->vid);
}

No Title Solution

I can understand a need for title. 1) SQL key and sorting and 2) menu navigation. But there are times when pages need to be without title for better looks. The solution could be simple (but need to be implemented):

1. In the future release, add a title field in addition to the key field. The title defaults to the key automatically; or...

2. To kill 2 birds with 1 stone, title can be formatted with font size, style and color. In this case, you simple set to smaller size and use the background color to make it completely invisible.

Custom node with flexinode & special PHPTemplate

Just an interim solution that does not require any writing of code (and may be forward compatible).

Create a custom node type with something like flexinode, named MyNode. Put whatever fields you need (including title).

Using PHPTemplate, make a copy of node.tpl.php to node-MyNode.tpl.php. You can remove display of the title in HTML in this custom template, but the browser will maintain the node title in it's title bar.

Samat

__
Personal home page | Rhombic Networks: Drupal-friendly web hosting

I just tried this

And it didn't work. I must be missing something. Can you give a little more detail on how to create a custom node using flexinode?

spoke too soon...

Eh, I think I spoke too soon. What I described with flexinode does not work. Drupal renders the heading outside of the node.tpl.php when it's a node view display.

Thus, you can make the heading dissappear in a teaser display (which isn't really useful), since that heading is rendered within node.tpl.php. But, for node view pages, the heading remains.

So... the obvious solution... which then is absolutely NOT clean, mess with the main page.tpl.php to specifically not print out a heading for that page if the title matches a page.

I have an example up at:

http://www.hotnudiegirls.com/~xjjk/blogs/drupal-4.6.0/node/25-a_node_pag...

(pardon the mess, it's a test installation for when I migrate my main site over to drupal. it will be deleted soon)

If there only a few page titles, you could probably define an array in the PHPTemplate file page.tpl.php and make sure the node being displayed is none of those pages. If you don't know PHP that well I can devise the code for you, but like I said earlier, this isn't very kosher and is a hack. Sorry for the mistake and being misleading!

__
Personal home page | Rhombic Networks: Drupal-friendly web hosting

How to do this with PHPTemplate and CSS

I just thought about the correct way to do this with PHPTemplate and CSS. It still would only work efficiently with a small number of pages you wish to do it for.

The idea is inspired from things like the URIid extension for Mozilla Firefox. Basically, we add a new class to our body tag so that we can hide what we want using CSS.

In the PHPTemplate theme, in page.tpl.php, I changed my body tag to look something like:

<body <?php
 
print theme("onload_attribute");
  if (isset(
$node)) {
    echo
" id=\"node-" . $node->nid . "\"";
  }
 
?>
>

This will create a ID tag that you can then, in your CSS style sheet, use to select for the page. Say the id of the node whose title you want to hide is 42. In your CSS stylesheet:

div#node-42 h1 {
  display: none;
}

I don't know why I didn't think of this sooner. This method is very simple and requires minimal modification of PHP code.

Edit: Since the these node classes are unique, they should be IDs. Changed above code examples to reflect this.

__
Personal home page | Rhombic Networks: Drupal-friendly web hosting

this doesn't seem to work for me

I changed my theme style sheet (using box_grey) to adjust h2 content-title (which is the style for this bit). But it doesn't work. Ideas? My node is correct.

A solution that worked for me (!)

I had a need to remove the title from a page that I was using as my homepage.

The solution tamasrepus suggested would have worked if node were passed down to page.tpl.php but in phptemplate it isn't (at least not in drupal 4.6). But his idea was on the right track. You can use the title of the page instead.

Follow this 3 step process.
Step 1. For every page which you actually don't want to show in the main content area, give your page a distinctive title without any spaces in the title. Choose something that is unique enough but doesn't look bad ('cos it'll still show in your browser's window-title). In my case I gave this page a title = 'HOME'.

Step 2. Then you edit the page.tpl.php in your theme directory to put the following:

<body <?php print theme("onload_attribute");
    echo
" id=\"title-" . $title . "\"";
?>
>

in place of this

<body <?php print theme("onload_attribute"); ?>>

For me, this placed id="title-HOME" as the attribute of my body element.

Step 3. Put the following at the bottom of your style.css :

body#title-HOME h2[class="page-title"] {
display: none;
}

What this is saying is : do not display any h2 element whose class attribute equals "page-title", if the h2 is under a body element has an id attribute equal to 'title-HOME'. The "page-title" class is set by drupal.

(In my case the title was being displayed as an h2 heading. Make sure it is same for you by looking at your browser's source. Else, you'll need to replace h2 above with whatever the element is.)

In your case 'HOME' should be replaced by whatever distictive title you give. The only caveat is to not leave spaces in the title (use underscore instead if you have want to use more than one word).

You'll need to put a similar block in your CSS for every title that you want to hide.

Have fun!

better solution (found looking for a workaround for IE)

The solution above works with firefox but not with Internet Explorer. Microsoft doesn't seem to conform to the CSS standard.

I discovered a simpler solution. Edit page.tpl.php in your theme dir and change the line that checks title != "" to title != "x". Then simply give x as the title to your page and it shouldn't show up.

No need to do the steps I indicated above !

Why not a comment sequence?

In the online handbook, it says you can use an html comment < !--This would be unseen --> as a title. I tried it, and it doesn't work. It's converted to &lt and &gt codes in the page. I tried it as raw input and that didn't work either. Apparently the title portion is handled differently than the body.

Wouldn't it be simpler to allow it to index these comments and display them as a comment - ie: not there.

Just a thought.

Titles and Filters

+1

I agree. The same should be done with the block titles. In 4.5.x you could put a comment or even any HTML in the title. In 4.6.x this got disabled.

What if you want graphical title, a PNG or even a SWF? In 4.5.x it was still possible. These unasked changes make it impossible for me to upgrade to 4.6.x because I have made a couple of sites based on this removed feature.

It would even be better to let node titles be handled by filters. If HTML is not filtered from the text body then it should not be filtered from the title either! The same can be done with block titles.

That way the developer is not imposing his choice be it is left to the user to decide.

+1

+1
I think perhaps submitting an actual feature request would get people noticing.

PHPTemplate solution

See http://drupal.org/node/28537 and my comments for another solution using PHPtemplate.

I'm still wondering how to replace the title with an image or Flash animation (for special fonts etc.).

Enable customizing of "Title" field on node forms

I found an interesting patch.

Enable customizing of "Title" field on node forms
http://drupal.org/node/10056

now *is* possible

HEAD has this feature today. will be in 4.7. see http://drupal.org/node/22218

This worked for me

I just stuck this:

h2 {
margin-bottom: 0px;
font-size: medium;
margin-top: 0px;
}
.page-title {
padding: 0px;
margin-top: 10px;
margin-bottom: 10px;
text-align: center;
display: none;
}

at the top of my content that I put in the node you created. Make sure you have the correct format selected to validate the code.

how?

I want to be able to not display the page title on a couple of pages, so was looking at this answer. Exactly what tags and things do you need to get this code to work and do the tags need to be on seperate lines or anything? I'm very new to php, so sorry if this is a stupid question.

Take a closer look at:

Take a closer look at: Automatic Nodetitles.

---------------------------------------------
last projects: www.happyfaces-kinderschminken.de - www.3p-consulting.com

I tried that

All it does is hide the title FIELD, and then let you auto generate a title. It doesn't let you hide the actual title.

I personally just want a little check box for every piece of content, just under the title field that says "display title." Unchecking it would just not display the title.

I did this by

I created a custom field called hide_title through CCK.

Then in the page template, I check for this variable, if it is set, then don't write out the title line.

Sorry that I can't be more specific, but that's the gist of it.

Hope that helps.

I need to know how to do

I need to know how to do this, can somebody post the details??

CSS in the game...

Since I had a content-type that I didn't want to show the title of it, I copied the node.tpl.php to a new file called node-page.tpl.php (this is the content type I needed to remove the titles from).
After trying to figure this out, I tried something else. I added to the end of the node-page.tpl.php the following html-css:

<STYLE type="text/css">
   H1 {display:none}
</STYLE>

.. and it worked! Remarkable !

Note: My title is using the h1 heading, change yours as needed.

I hope this helps ... !

removing all titles in nodes with CSS is easy

I'm working with 4.7.x. and the burnt theme.
A very easy way to remove all those titles is to change the h1 that is responsible for the title in the page.tpl.php of the theme
<h4 class="title"><?php print $title ?></h4>
into h4 or h5 or some tag that you probably won't use in the future. Then you change/add a style to your style.css in the theme's folder like this
(basically the same method as mentioned by Ldectus_gr and others):


h4 {
dispaly: none;
}

and that's it. It doesn't show up anymore.
Now, I don't really understand why I couldn't just change the title class in there, I've tried to find where it is styled and I didn't find it in the drupal.css and neither in the style.css, strange...

Hiding the Node Title by Node Type

Here's a page about hiding the node title for a specific type of node in drupal 5.x http://drupal.org/node/138910

palantir.net | moonsdawn.com

palantir.net | fluxpickle.com

Content Type without Node Title

Wow, this is SEVEN(!) years old feature request and still nothing happend..?! Especially nowadays when many developers use CCK for various purposes..

Does anyone have a clue how to create Contet Type without mandatory Node Title?

Any sugestions welcome!!

Thx, Loutka

Didn't bother reading the

Didn't bother reading the whole thread. But i've used http://drupal.org/project/auto_nodetitle in the past to do what i 'think' your asking for.

my solution.

If you want to create one node without title inside body tag,
1. In page.tpl.php of your theme, find <?php if ($title)....
In my theme, the whole line is <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
2. then inside if statement add another if and else statements, that print the title inside h2 tag if the title is equal to 00000.

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

Then when writing or adding node, Input the title of node as 00000.

==

In title tag,
<title><?php print $head_title ?></title>
You can also add an if statement, like

<title><?php
if($title=='00000') print 'SITE NAME' ;
else print
$head_title ?>
</title>

Array

instead of just 00000, you can add more options by having an array..
you should also disable automatic url alias when creating a node and manually input url alias.

enjoy guys

Easy!

This is easier than I thought it would be. Just whip up a new module and tap into nodeapi. I'm setting a default title when the node is prepared for add/edit, but there are all kinds of ways you can use nodeapi. Like this

<?php


function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch (
$op) {
  case
'prepare';
    if(
$node->type == 'my_type'):
     
$node->title = 'My custom default title';
    endif;
  break;
}
?>

... match your parentheses !

or that code will crash :)

How about 'has_title = false'

My suggestion is just to change has_title property for node type. I haven't found any solution to do it from UI, but it possible to change at least if you create new node type programmatically, i think there is also functions to update node type properties (or just update directly to DB).

<?PHP
function MYMODULE_install() {
    $t = (object)_node_type_set_defaults( array(
    'type' => 'mytype',
    'name' => 'MyType'
    'module' => 'node',
    'description' => '',
    'custom' => true,
    'modified' => true,
    'has_title' => false,  // here is the catch
    'has_body' => true,
    'title_label' => 'Title',
    'body_label' => '',
    'locked' => FALSE,
    'min_word_count' => '0',
    'orig_type' => '',
    'help' => '',
  ));
  node_type_save($t);

.. that removes title field, and it isnt added to form.
Notice that title field is used many places, and now those places has left empty, places like title in 'workspace' module, and title in 'forum' module.