Forums / Developer / Help with code: Comments in frontpage

Help with code: Comments in frontpage

Author Message

Shurbann Martes

Friday 02 January 2004 11:05:08 am

Im trying to make all the comments to shwo up in the frontpage of my site:

- The idea is to show them sorted by published date.
- The name of the news of wich the comment is made is shown.
- If there is a news with more then 1 comment, it will show only one, the most recent comment.

This is the code:
{let comment_parent_array=array(0) comment_list=fetch(content,list,hash(parent_node_id,2,limit,6,depth,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array('comment')))}
{section name=Comment loop=$comment_list}
{section show=not($comment_parent_array|contains($Comment:item.id)) comment_parent_array=$comment_parent_array|insert($Comment:item.id)}
{node_view_gui view=line content_node=$Comment:item}
{/section}
{/section}
{/let}

line_view_comment:
{let ParentNode=fetch(content,node,hash(node_id,$node.parent_node_id))}
<div class="small">{$node.object.published|datetime(custom,"%H:%i")} <a class="small" href={$ParentNode.url_alias|ezurl}>{$ParentNode.object.name|upfirst|shorten(20)}</a></div>

So 1 and 2 is accomplished but the last part I don't know how to do it.
Do you have some ideas?

-Shurbann

Shurbann Martes

Saturday 03 January 2004 3:03:39 am

Mabe I was not clear enough:

I want to just show the latest commment of each news.

Marco Zinn

Saturday 03 January 2004 4:14:10 am

Hi,

well, i didn't completely understand the code:
{let comment_parent_array=array(0) comment_list=fetch(content,list,hash(parent_node_id,2,limit,6,depth,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array('comment')))}
{section name=Comment loop=$comment_list}
{section show=not($comment_parent_array|contains($Comment:item.id)) comment_parent_array=$comment_parent_array|insert($Comment:item.id)}
[..]
What is $comment_parent_array used for? You want to store the IDs of the articles in the array and check, if and ID already exists?
Nice idea :)

But you say, it does not work.
First, I thought "use max=1 in the loop", so you will get only one comment. But you seem to fetch all commments with one single fetch.
Then, maybe you should try something like this (pseudo-code ;) )
Fetch all articles
section loop=article
fetch all comments, where the current article is parent node, sorted by date
section loop=comments, max=1 show=comments
print comment with parent node name
/section
/section

This might work, but the drawback is, that you need LOTS of DB fetches.

Marco
http://www.hyperroad-design.com

Shurbann Martes

Saturday 03 January 2004 4:23:50 am

Ok Marco....

Thanks for the pseudo-code. I'm only going to put the last 8 comments more or less. So it means 8x more fetches :(

Yeah the idea was to put the ID's of the articles in the parent_array and check if it already exist in the array and if this is the case don't show the comment.. .
I think I have the well known problem with namesection. I have to print the array to see if it the array exist in that section.

But thanks for the idea. If I don't solve the problem above I will implement the code as you told me.
Cheers!!

-Shurbann

eZ debug

Timing: Jan 19 2025 01:13:27
Script start
Timing: Jan 19 2025 01:13:28
Module start 'content'
Timing: Jan 19 2025 01:13:28
Module end 'content'
Timing: Jan 19 2025 01:13:28
Script end

Main resources:

Total runtime0.1726 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 590.1016180.8281
Module start 'content' 0.00780.0099 770.929797.8828
Module end 'content' 0.01770.1547 868.8125528.2969
Script end 0.1724  1,397.1094 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00392.2489200.0002
Check MTime0.00150.8871200.0001
Mysql Total
Database connection0.00150.842010.0015
Mysqli_queries0.101858.96861410.0007
Looping result0.00140.79991390.0000
Template Total0.154189.310.1541
Template load0.00110.640310.0011
Template processing0.153088.659610.1530
Override
Cache load0.00070.400910.0007
Sytem overhead
Fetch class attribute can translate value0.00100.563810.0010
XML
Image XML parsing0.00040.205710.0004
General
dbfile0.019111.0492200.0010
String conversion0.00000.004030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs