By gnotorious on
For example, the post date, posted by, "Add a Comment", and Taxonomy term at the bottom. These things are great for page views but unnecessary for teasers and just add clutter and make it hard to distinguish between the teasers in the list.
I've read a bunch of things about creating templates but I haven't had any luck doing it. Is there an easier way or could someone point me to a good step by step tutorial that doesn't assume I already know what I'm doing?
Thanks!
Comments
Hi there
In your theme folder, in the "template" file node.tpl.php, you can use logic with the variable $teaser, a boolean, to display what you want in the teaser view. $teaser is TRUE when the teaser has to be displayed, and FALSE when the node has to be shown in full view. You don't set that variable : you use it. And you use it for "logic".
For example :
Look in the above code for the two places where I use (added)
&& !teaserin the if condition.The variable $content in node.tpl.php is the entire content (body) of the node or the teaser, i.e. $node->teaser. You are left with one less thing to worry about with that variable.
Now, as far as hiding the "Add a Comment" link, you could very well hide ALL links, hence add
&& !teaserin your node.tpl.php file :OR, alternatively, you can use a CSS rule with a hook to that link to hide that PARTICULAR link in your theme style.css file:
If you want to apply all this tweeking only to nodes of a particular content type, copy and paste the content of
node.tpl.php in a new file inside the same folder with name : node-content_type_name.tpl.php
with the changes you need (and I gave you the code above, so it should be easy).
For example, if you have created a content type with name "news" then
1- create a file with name node-news.tpl.php
2- copy what's in node.tpl.php in node-news.tpl.php
3- make the changes...
You don't need to tell Drupal about the existence of a content-type-specific node template file.
It will look for one. If it does not find one, it uses node.tpl.php.
Caroline
A coder's guide to file download in Drupal
Who am I | Where are we
11 heavens
Thank you Caroline! I
Thank you Caroline! I haven't had a chance to attack this yet but I think I should be able to get where I need to from this.
you're welcome
It looks like a lot of code up there but it's because I copied the whole content of the node.tpl.php file. In that code, I only changed 2 lines, where I add
&& !$teaser. I wish I could put these "edit" in bold, so it's clearer.Editing template files (and overriding themable functions) is easy and give us so much power over that wild beast that is Drupal.
Try it!
Caroline
A coder's guide to file download in Drupal
Who am I | Where are we
11 heavens
Teaser view
Hi,
I saw your poston drupal (http://drupal.org/node/133236) and tried to do what you said. Oddly, adding the code seems to remove nothing from the teaser view, but adds the date and comments again to the page view. Obviously I am doing something wrong, but I don't understand what. I have made a new file node-mdb_movie.tpl.php and added code below
It's for a movie database, and I want to show less info in the teaser view, just the name of the film and the cover image.
any thoughts?
thanks
Try Views
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
a ha!
ok, installing now. thanks for the tip.
ed
Thanks for the help
This one post has really expanded my understanding of how Drupal works, I'm very grateful.
Now i understand how to alter the look and feel of loads of elements which had been bothering me.
I think that the Drupal community is brilliant, whenever you have a problem there is usually a solution already posted our at least one which contributes to your own understanding and then lets you solve it yourself.
Well, just wanted to thank
Well, just wanted to thank you for that bit of code
&& !$teaser. It was buggin me before.Note: you may note notice the changes rite away if you are using some sort of caching mechanism, logging in may update the page.
Youfolder.com
Share what's in your folder for the Hispanic community in Canada.
Css question
Thank you very much for the post. I was able to remove the terms from the teaser.
I now wish to remove the "send to friend" but keep the "read more". You suggest using
.comment_add {
display:none;
}
but I do not know where to insert this in the style.css as it does not mention teasers at all. Where in the style.css should I made the change.
I think the "send to friend" is called "send-link" but I am unsure. I've only found:
li class="last send"> a href="/send/send/38" class="send-link send-send send">send to friend /a>
Love and light
hi yogayak, did you find an
hi yogayak, did you find an answer to your solution? Im on the same boat as you are. I want to remove "write comment" from the teaser section and leave "read more".
I far prefer CSS methods
I far prefer CSS methods (when viable) as they preserve the output (especially links) for SEO optimization).
Drupal tends to force you to override something (display:none to .submitted to get it off the home page) and then display where you want it (display: inline in block-views, for instance). This is a relatively painful way to get things done, especially for new Drupalers, as it can be hard to know where you want to turn something back on! and CSS is not a logical/expression language.
~kwt
Teaser/Body configuration for CCK users
I went down this path originally for tweaking the look of my teasers/body, but then realised that much of this can be done from the CCK configuration page (if you are using CCK of course)
Under the 'Display Fields' tab of your Custom type, there are a number of columns which allow you to customise the way your data will appear:
I found I could remove pretty much all of my custom code from the tpl.php file once I got my head around these page.
re:Teaser/Body configuration for CCK users
Thanks for the help! I was having this problem w/ some php code I'm using in a text field showing up in the teasers, and I guess I missed the configuration options. Now everything is working great!
sort of works but not quite
I added the css snippet to my style.css file but unfortunately this removes the "add comment" link globally, not just from the teaser view ie. "add comment" is no longer visible in teaser view as well as in the full node view. How can I implement it so that the link is visible in node view but not in the teaser view?
many thanks
Ole
Change the style for the teaser only
You can try this:
This is setting the style only for the teaser block. Of course you need to make sure that your teaser output is actually wrapped in a teaser div, which I think it is by default.
.teaser comment_add {
That does not work. It only works when you don't add 'teaser', but that's not what we want...
div.node-teaser
div.node-teaser .comment_add
{
display: none;
}
Leave out the things, but keep the read more
You may want to keep the read more link
Love, Live, Laugh
To Clarify:
This is a long thread. I think most people arrive here wondering how to remove 'add new comment' from the teaser. Mojah's comment, placed in your node.tpl.php file works nicely. you may have to replace your existing print $links code. Worked for me in Zen.
Thankyou
Thanks Caroline for the
&& !$teasertip.This Mojah's comment also worked perfectly for me. Thankyou.
--
Gomez
Just what I needed. Thanks!
Just what I needed. Thanks!
removing comment link on teasers
this works beautiful on D6.5
thanx Mojah
Http://www.reloadmedia.com
Http://www.reloadmedia.com
How to remove add new comments in 4.6?
Can you please advise me for how to remove add new comments links in drupal 4.6x.?
I cannot update it to drupal 5 or 4.7 immediately as i need to redo a lot of modification in my coding.
And I really need to remove add new comments links from the node for now.
Thank you for your understanding.
Thank you, Caroline! Coming
Thank you, Caroline! Coming from a WordPress background, I'm more comfortable modifying the display of my sites by calling variables and using logic in templates. This seems to be done a little less in Drupal, in favor of Views, CCK and ConTemplate.
My review of David Mercer's "Drupal: Creating Blogs, Forums, Portals and Community Websites"
It works great !!
Thank you for the code !!!! BRAVO....HAIL TO THE HACK !!
Brilliant, simple, works.
Brilliant, simple, works. Much appreciated.
Remove only one terme of $links
Hi Caroline,
I am having trouble using the information of this page to be able to remove only one of the links in $links.
What I want is to remove the Attachment link as I am using a piece of code to display it with an icon.
Above all, the attachment link in the teaser is not a direct link, so to me it is not useful.
I didn´t manage to use the CSS turn around.
Your code show how to remove all $link and display one, but I want the oposite.
I believe the field is $attachment, but not sure.
Could you help me with that?
Michaël
Thank You
I was looking for a cool way to hide the terms (taxonomy) on the Teaser. Found this topic and just did what Chill35 said and it worked like a charm =D
I added the following on my node.tpl.php inside my theme folder:
and it's all ok now ^^
Thank you Caroline
&& !$teaser did the work!
Theme settings
Submitted by user and date go away when you change the settings in Admin >> Themes. And I don't get the terms in teaser view with Garland.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
terms in teaser view in Garland
Garland does show terms in the teaser view. You probably modified your template so that it doesn't...?
Caroline
Who am I | Where are we
11 heavens
Nope
I have not modified any theme code on any of my sites, other than the CSS.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
only in global settings
For clarity (I got confused): this option only appears in the global settings for admin>build>themes, not in specific theme's settings
-Rafael
http://mediaisland.org
good stuff
subscribing... newbie
Subscribing
Tried this on a new site, works, liked it.
http://www.faunapolis.org/
Subscribe
Need this in the near future. Thanks!
I got the same proble...
Yep, right..!!! user node, submit date, taxonomies, comment donot need to show in teaser but in full preview is good to show, just like http://www.usmagazine.com , right ?!
I just posted the same issue but no one couldn't give a favor they're just referring me to another link.
Finally, i'll do to work with the code that gave on this post but i'm not sure it's gonna work...I hope all friends in this issue could give me a hand while i got a problem
I posted the node.tpl.php
I posted the node.tpl.php code you asked for today.
Remove terms altogether
On a related note, I'm trying to remove the terms display altogether for nodes. I remove the obvious lines from node.tpl.php, and when logged in the terms don't appear, but they do to anonymous users, or at least one term does.
Here's my node.tpl.php:
As you can see there's no "print $terms" in there at all, but it's still printing some terms for anonymous users.
I've cleared my broswer cache, tried different browsers, but the behavior is the same...
Steel Rat
My Drupal Sites:
RPGMapShare.com
Infinite Ordnance
Malvern Rouge Valley Youth Center
Clear Drupal's cache
Drupal has its own caching for anonymous users.
How to clear Drupal's cache : http://drupal.org/node/42055
Caroline
A coder's guide to file download in Drupal
Who am I | Where are we
11 heavens
Thanks Caroline. The terms
Thanks Caroline. The terms eventually went away.
Steel Rat
My Drupal Sites:
RPGMapShare.com
Infinite Ordnance
Malvern Rouge Valley Youth Center
Remove terms altogether
Oops, got duplicated...
subscribe
subscribe
Try this
Garland node.tpl.php modified for minimal teaser
Small change in node.tpl.php for Garland
I think the
// full node in a page viewhas to move inside the prior if statement.The following works perfectly for me. Thank you!
Not sure how I missed that...
Added the comment whilst posting the code; never a good idea :-)
Happy that it worked for you after you fixed my foolish error!
Pete.
thanks
was looking for this and works.
For sky theme:
I have little different
I have little different problem. I would like to display node teasers with only titles and texts in right or left blocks. Can't figure out how to get rid of the links in "submitted" class (post date, posted by, etc), but only for the teaser displayed in blocks.
subscribe
subscribe
node template
you can also create node specific template if you only want to change the look for particular nodes. For example, you can create a file called "node-yournodetype.tpl.php" as I described here for customizing the look of taxonomy terms.
subscribe
does anyone know if this works for teasers in views? There's all this added stuff I need to remove.
One question. I want that
One question. I want that comments show authors name, but that this is not shown as a link. Just the name without link. How can this be done? I suppose it has to do with playing with $links but I don't want to suppress the authors name, only disable it as a link. Any hint?
Alternatively, to hide the
Alternatively, to hide the terms you could use the term_display module.
The good thing about this solutions is - you don't need to do any coding or template/CSS modifications.
The bad - this module will just plain always hide the specified terms/vocabularies, i.e. you won't have control over whether you want to show them in page view and hide them in teasers. Works quite well for some vocabularies, though.
www.fxsoftwaresolutions.com
Siberia Theme's node file is different
I would like to remove the submitted by and terms fields from the teaser but when I add the code from this post to the teaser file, it removes the submitted by from both the teaser and the full post and does nothing with the terms in either.
The code for the node file in this theme looks significantly different than shown in this post. Here it is:
There doesn't appear to be any reference to the teaser in the CSS so I don't know that I can do anything with that.
Try this
Pete.
Thanks!
Yes, that does actually work. I found too that if I just copied the whole code rather than trying to insert the teaser stuff that that worked as well and actually handled the taxonomy terms on the full view in a nicer fashion so I just kept that.
Thanks for your help. I'm teaching myself this as I go.
Thanks Pete
This code worked well to hide my taxonomy on specific node types - in drupal 6!
thanks!
thanks!
Controlling the display of elements with CSS?!!
Is it possible to control the display of different node types with multiple CSS files, each for a specific node?!!
"... read more" appears on Node and comment hidden
I am trying to get the "add comment" and taxonomy terms to hide from my teaster view. I want to keep the "...read more" link on the teaser view.
I have tried the following and it leaves the "...read more" link in the teaser, but it also appears on the node view now. Also, the "add comment" link is gone from the teaser (which is good) but gone from the full node as well. Can anyone help me out? I am absolute php novice.
Thanks,
Dave
_
Looking at the code, there are two conditional statements -
<?php if ($links && !$teaser): ?>which means 'Do this if $links is true and $teaser is false, and
<?php if ($terms && $teaser) { ?>which means 'Do this if $terms is true and $teaser is also true.
We're not here to provide a PHP 101, but does this help?
Pete.
Adding "else"
Pete, thanks for the help. That got me sorted with my language. One final question. I have read some php tutorials at w3schools about "if else" and organisation here looks different. Where could I put the "else" html that I want to show if the conditions I set are false?
I realise these are simple questions, but I do not know where else to look for basic php help in Drupal. If you know of another resource, please let me know.
Dave
_
Hi Dave.
You could do something like this :-
Taken from my copy of O'Reilly's 'Programming PHP'; £8.00 from EBay :-)
Pete.
Thanks..
Thanks..
THANKS!!!
To mojah and Caroline: Thanks for the examples. Caroline, your logic worked beautifully. I didn't realize it was so easy, and I'm no php expert by any means. It became apparent real quick that the "!" was used as a "not" function with the boolean logic...I had seen this used with conditional statements for IE. It was then that I had the "lightbulb" moment.
I actually learned something about php, today. :)
Michael
Mojah's code work great
Without much sweating i have used Mojah's code and it worked great on my drupal 6x site.
But this issue do not happen for all themes. some themes are doing this (removing/disabling) add comments link from the teasers automatically. However few themes are not.
I would rather expect Drupal to provide this option as core feature some where in post settings in administration and that would help every one.
you can look at it at http://www.balikampung.com/articles
thanks again
Take a look
at http://www.lullabot.com/articles/great-pretender-making-your-data-act-field
NancyDru
hiding div layers
Greetings,
There lots of good advice here about how to hide default variables, but how do we go about hiding a div layer from a teaser?
Thanks
Kevin
Hidden
You should look at a CSS tutorial for hidden divs.
NancyDru
Hi Nancy, I thought of that,
Hi Nancy,
I thought of that, but if I hide a DIV in css than it will be hidden in both the teaser AND the full node view, wouldn't it?
No
Teasers have a class of node-teaser added to them.
NancyDru
I tried this: Hide me from
I tried this:
div class="addtoany"
In CSS:
.addtoany .node-teaser {
display:none;
}
That does not work. Can you see what I'm doing wrong? Many thanks for your help.
In order
The classes need to be in the order they are encountered in the HTML. In this case ".node-teaser" comes first.
NancyDru
Perfect! Thanks!
Perfect! Thanks!
remove from comment module
How to remove the login/ register message from the comment module?
Edit: http://drupal.org/node/232310#comment-5003814
Well...
The easiest way is to allow anonymous commenting, but you will start getting lots of spam.
Use Firebug to see if it has a special class (I think it does) and add CSS to not display it.
NancyDru
This is totally ridiculous
This is totally ridiculous that the easiest way to remove the "Add comment" is through the theme. Why is there not an option within Drupal core?
Actually
If you don't want comments at all, then just disable them in the node or the content type.
NancyDru
Remove links from teaser while maintaining them in full page
In Drupal 7, the codes in node.tpl.php of themes\templates are different from those showed in earlier comments. I had to do it different but I used Caroline's instructions to arrive at the solution. Open file sites\all\theme\yourtheme\templates\node.tpl.php
Look at around line 38 to line 43. Look for:
add && !$teaser after $display_submitted
It should then be like this:
Save your file and go have a look.
Manage display page
Most things can be hidden in the "Manage display" page for the Teaser display.
NancyDru