List of links to related articles (by keyword)

Author Message

Chris Lyzg

Monday 19 January 2009 6:44:16 am

I've found this code:

{let 
related=$node.object.data_map.keywords.content.related_objects}
{section show=$related}
<h2>Related documents</h2> 
<ol> 
{section name=Related loop=$related}
<li><a href={$:item.url_alias|ezurl}>{$:item.name}</a></li> 
{/section} 
</ol> 
{/section} 
{/let}


http://ez.no/ezpublish/documentation/customization/components/datatypes/ezkeyword/automatic_object_relation



It's working fine...

...but I need something more, <b>limit this list to 5 items, from specified node and sorted by published date.</b>

How to develop this code? I couldn't find any solution at ez.no. I'm not a programmer and need your help.
I think it would be very usefull for many other beginners also.
sorry for my english :)

André R.

Monday 19 January 2009 12:50:55 pm

templates/content/datatype/view/ezkeyword.tpl from a recent project:

<p>{"Keywords used in this article:"|i18n("design/mydesign/keywords")}</p>
{def $keyword_array = $attribute.content.keyword_string|explode(',')
     $keyword_count = 0
     $keyword_string = ''}
{foreach $keyword_array as $keyword}
    {set $keyword_string = $keyword|trim()}
    {set $keyword_count = fetch( 'content', 'keyword_count', hash( 'alphabet', $keyword_string ) )}
    {if $keyword_count|gt( 1 )}
        <a href={concat('content/keyword/', $keyword_string)|ezurl}>{$keyword_string|wash}</a>
    {else}
        <span>{$keyword_string|wash}</span>
    {/if}
{/foreach}
{undef}

With this you can easily set limit using max parameter on foreach, and you can also add classid in url as parameter if you want to filter on that.
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/modules/content/fetch_functions/keyword_count

But look like you want to link directly to the articles that use same keyword, so you should probably look at:
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/modules/content/fetch_functions/keyword

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:33:34
Script start
Timing: Jan 18 2025 11:33:34
Module start 'layout'
Timing: Jan 18 2025 11:33:34
Module start 'content'
Timing: Jan 18 2025 11:33:35
Module end 'content'
Timing: Jan 18 2025 11:33:35
Script end

Main resources:

Total runtime1.3025 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.4766152.6406
Module start 'layout' 0.00570.0037 742.117239.4766
Module start 'content' 0.00941.2917 781.5938531.0156
Module end 'content' 1.30110.0013 1,312.609412.1250
Script end 1.3024  1,324.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2604160.0002
Check MTime0.00130.1018160.0001
Mysql Total
Database connection0.00100.078410.0010
Mysqli_queries1.257496.5370540.0233
Looping result0.00050.0361520.0000
Template Total1.269397.520.6347
Template load0.00230.179720.0012
Template processing1.267097.274820.6335
Template load and register function0.00010.007510.0001
states
state_id_array0.00120.090710.0012
state_identifier_array0.00150.113520.0007
Override
Cache load0.00200.1531250.0001
Sytem overhead
Fetch class attribute can translate value0.00040.032020.0002
Fetch class attribute name0.00120.094730.0004
XML
Image XML parsing0.00070.055020.0004
class_abstraction
Instantiating content class attribute0.00000.000630.0000
General
dbfile0.00080.0599170.0000
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs