Hide empty trackbacks and comments

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
mo
Regular
Posts: 40
Joined: Sun Jan 27, 2008 11:33 pm
Contact:

Hide empty trackbacks and comments

Post by mo »

Hello there!

I am using the latest S9Y in combination with a slightly modified carl template. Below each blog entry, the section with trackbacks and comments take a lot of space, even when there are none. Also, I'd like the "write comment" area to be hidden by default, and only show when the user clicks the heading

What's the easiest way to make that happen? Embedded JavaScript inside the template?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

You could hide the block with Javascript. You could also use CSS, but you'd have to modify the template a little bit. You could include the Javascript in a HTML Nugget in Head event plugin.

I'm afraid I don't have the Javascript for hiding a <div> on hand. I'd recommend a Google search. When you find it, just install the Head Nugget, copy your Javascript into it, and make sure that it's set to not allow markup.

I'm surprised the trackback and comment section is taking up so much space. I'd edit the carl_contest/style.css and change the margins and padding for .serendipity_section_trackbacks and .serendipity_section_comments.

Whenever I edit CSS, I find that Firefox and the Firebug plugin are extremely helpful. They take a multiple-hours task down to a dozen minutes.

If you need anything more specific, let us know!
Judebert
---
Website | Wishlist | PayPal
mo
Regular
Posts: 40
Joined: Sun Jan 27, 2008 11:33 pm
Contact:

Post by mo »

Thank you for your quick answer. I have a lot of short postings, that's why it doesn't look too good.

The problem is not the embedded JavaScript. I want to hide both trackback and comments only if there are none, and I'm unsure how to find out about that - I can only see a call to printTrackback inside the template.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Ah. In that case, you'll want to use a little Smarty in the entries.tpl.

Find the <div> with the comments (it'll probably have the class serendipity_section_comments). Surround it with an {if} statement:

Code: Select all

{if $entry.comments > 0}
 ... regular comment stuff ...
{/if}
You can do the same with the trackbacks; there, you'll want to use $entry.trackbacks. Just be careful: the link allowing other bloggers to create trackbacks is usually in that <div>, and you don't want to eliminate it unless you also want to eliminate any trackbacks you might get. Just move the link outside the block, so it always shows up.

If you find that the whole thing is in one bigger <div>, and you want to display the whole thing ONLY when there are trackbacks, comments, or both, use this {if} instead:

Code: Select all

{if $entry.comments > 0 || $entry.trackbacks > 0}
... giant trackbacks and comments div ...
{/if}
Of course, you'll still want to be careful with the trackback link.

That should do what you want! We'll be here if you have any other questions.
Judebert
---
Website | Wishlist | PayPal
mo
Regular
Posts: 40
Joined: Sun Jan 27, 2008 11:33 pm
Contact:

Post by mo »

Works great so far. In case there are no trackbacks, I surround the whole trackback block with a hidden div. I guess automatic trackbacks will still work then?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

That should work the way you want.
Judebert
---
Website | Wishlist | PayPal
Post Reply