Preview Comments in Entry-Overview

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Sandrachen
Regular
Posts: 6
Joined: Fri Nov 14, 2008 9:51 am

Preview Comments in Entry-Overview

Post by Sandrachen »

Hello,

i tried to figure this out on my own, but it didn't quite work the way i wanted.

On my Entry-Overview (Blog startingpage) i'd like to have a preview of comments at the bottom of the entry.

Like this:
________________________________________________________________
Subject

yadda yadda yadda body

Comment Preview

Entry Footer | Written by bla | Categories | Comments (2)
________________________________________________________________

The Preview should be something like "Name says: Yadda bla... read more >>".


I tried to modify my entries.tpl like this (pseudocode):

Code: Select all

foreach entry.comment
 <p>comment.body</p>
that just printed the body of the last comment, which somehow confused me.


I also tried the serendipity-smartyfunction for printing comments, that worked - but i dont want all the mail and homepage-stuff there. i then tried to modify the smarty-function, but i'd prefer not to modify any corefiles.

my last idea was to use serendipity_fetch_comments which is also called in the print_comments-function and assign the return value to a smarty variable - but i couldnt figure out how to do that.


soooo, in short words: can anyone help? ;-)

Thanks,
Sandrachen
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Preview Comments in Entry-Overview

Post by garvinhicking »

Hi!

Why do you give pseudocode and not the actual smarty code? If you only show comment.body, of course only the body of the comment will be shown. If you want to show other fields, you need to place the other fields like {$comment.author}. Have a look at comments.tpl for actual usage, that is used inside a blog entry.

Showing comments on the article overview will result in many database calls, and you will need to use the {serendipity_printComments} smarty function, you can specify the template= parameter to use a template other than comments.tpl to render your output with only the fields you want.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Sandrachen
Regular
Posts: 6
Joined: Fri Nov 14, 2008 9:51 am

Re: Preview Comments in Entry-Overview

Post by Sandrachen »

Hi Garvin,

for the test i wanted to only show the body of the comment, adding author and other fields later is not my problem.

I did a test-entry with 2 comments, body was "1" and "2". I then put the following code in my entries.tpl:

Code: Select all

{foreach from=$entry.comments item=comment name="comments"}
<p>{$comment.body}</p><br />
{/foreach}
So, i expected to see:
1
2

I saw:
2

That confused me.


But thanks for the information with the custom template. That could indeed solve my Problem. I just print the comments to a custom template.

Gonna try that - thanks for your fast help :-).


EDIT: That works, thanks :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Preview Comments in Entry-Overview

Post by garvinhicking »

Hi!

$entry.comments only holds the comment counter, no comment data. For that you need to utilize the printComments function to get the actual data. The actual comments are not read in the overview, which is why this will be a database overhead when you fetch it for every entry on the overview page.

:)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Sandrachen
Regular
Posts: 6
Joined: Fri Nov 14, 2008 9:51 am

Re: Preview Comments in Entry-Overview

Post by Sandrachen »

Oh ok, i see ... maybe using numbers as example text wasn't that intelligent ;D
Post Reply