0

I'm trying to retrieve other web contents / articles from inside another a velocity template.

What I would like to to get is a list with published articles of the latest version with structure name 'Game'. I tried to use search but with no luck at all. At the moment I have something like the following but still I don't have the result I want.

#set ($journalArticleLocalService = $serviceLocator.findService('com.liferay.portlet.journal.service.JournalArticleLocalService'))
#set ($languageId = $request.theme-display.language-id)
#set ($companyId = $getterUtil.getLong($request.theme-display.company-id))
#set ($scopeGroupId = $getterUtil.getLong($request.theme-display.scope-group-id))
#set ($DDMStructureLocalService = $serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalService"))
#set ($structures = $DDMStructureLocalService.getStructures($scopeGroupId)) 
#set ($obc = $portal.getClass().forName("com.liferay.portlet.journal.util.comparator.ArticleDisplayDateComparator").newInstance())

#foreach ($tmp in $structures)

    #if ($tmp.getName($languageId) == 'Game') 
        #set ($allArticles = $journalArticleLocalService.getStructureArticles($scopeGroupId, $tmp.getStructureKey()))

    #end

#end

#foreach ($article in $allArticles)

    #if ($article.getStatus() == 0)
        <pre>    $article    </pre>
    #end

#end

I'm using Liferay 6.2 sp8 with some extra patches

0x_Anakin
  • 3,229
  • 5
  • 47
  • 86
  • 1
    Would you please let us know the result of this code snippet? – Pankaj Kathiriya Oct 07 '15 at 14:32
  • Are you able to fetch the particular `Game` structure? – Prakash K Oct 07 '15 at 14:50
  • The result of this code is that it displays all articles with status == 0 but it wont show the latest version – 0x_Anakin Oct 07 '15 at 14:57
  • Do you mean that all version of a document are displayed or just it's not diplay in the right order ? Because in your code your never use your comparator – fabballe Oct 12 '15 at 16:02
  • All versions are displayed. What I was trying to accomplish is to retrieve the latest version of any web contents with structure 'Game' from within another web content velocity template. – 0x_Anakin Oct 13 '15 at 08:36

1 Answers1

0

Use getLatestArticle method when you want to get latest article from list of articles. Checkout the below link.

https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portlet/journal/service/JournalArticleLocalServiceUtil.html#getLatestArticle(long, java.lang.String)
Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25