Forums / Developer / List of links to related articles (by keyword)

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

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/Exponential/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