Liferay 6: how to get web contents by category

Below is the Java snippet to get the list of web contents which belong to a specific category.

public List<JournalArticle> getArticlesByCategory(AssetCategory category) throws SystemException {

	// Build query
	AssetEntryQuery query = new AssetEntryQuery();
	query.setAllCategoryIds(new long[] { category.getCategoryId() });

	// Run query
	List<AssetEntry> assets = AssetEntryLocalServiceUtil.getEntries(query);

	// Build result
	List<JournalArticle> result = new ArrayList<JournalArticle>();
	for (AssetEntry asset : assets) {
		try {
			result.add(JournalArticleLocalServiceUtil.getLatestArticle(asset.getClassPK(), WorkflowConstants.STATUS_APPROVED));
		} catch (PortalException ignored) {
			// happens if the asset has no JournalArticle associated ==> should not happen

	return result;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.