I have Liferay articles (at their latest version) and want to get their friendlyUrl. I know that the friendlyUrl is in the Layout table but I don't know how to map my article there.
The internet and Liferay's documentation don't seem to be of help
Get the articleId
Get the layoutIds it appears in
Get all Layout objects
For each Layout get the friendlyUrl
List<Long> layoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds(groupId, false, articleId); // all the layoutIds
Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId.get(x));
layout.getFriendlyURL();
Related
is there a way to refocus on the blog portlet after clicking next/prev. when i click those buttons it goes to the top of the page.
We are using liferay 7, with freemarker. We are kind of new with liferay
I suppose you mean to scroll to the blog portlet when you say "focus on".
In this case the mechanism it is pretty simple:
IF in the DOM there is an element with a specific id attribute AND the url ends with #the-same-id-attribute then when the page is loaded it will scroll to that element.
The blog portlet has a unique attribute by default, you should append it to your next/prev buttons URLs.
Ref:
Fragment Identifier
Im adding Documents with this snippet of code:
fileEntry = DLAppServiceUtil.addFileEntry(
repositoryId, folderId, filename, MimeTypesUtil.getContentType(strFile), filename,
description, changelog, in, srcfile.length(), serviceContext);
Documents are shown in Asset Publisher and Documents and Media Portlet.
After this im adding Vocabularies and Categories programatically, which are shown correctly in Categories Navigation Portlet. Then i'm adding the Categories to the documents. This Categories are shown in Asset Publisher correctly, but when i select a Category in Category Navigation Portlet i don't get any result. In Documents and Media Portlet selection by Category is working without problems.
This is the code i'm using to attach Categories:
DLAppHelperLocalServiceUtil.updateAsset(userId, fileEntry, fileEntry.getLatestFileVersion(), categoryIds, null, null);
I would be very glad anybody got a hint.
Problem was they did not have same scope.
I want to use a custom layout for articles based on their categories' custom layouts.
sports category layout - sports article layout
science category layout - science category layout
Thank you for any reply.
UPDATE:
I have an idea on how to deal with this, as the answers below kind of give me some hint. I need to be able to get the category layout on the article item page. I know this is tricky but Joomla has all the stuff to do it, so what's the best thing to do now?
Well, I found much easier and seamless solution to do this kind of trick. Once you overrided category layout, you should have placed something like "sports.xml" in your template folder, otherwise it would not work with your menu item (because joomla blog.xml have hidden field about layout, and you should override it to make it right). In this sports.xml you can add another field for article layout - like
<field
name="article_layout" type="componentlayout"
label="JGLOBAL_FIELD_LAYOUT_LABEL"
description="JGLOBAL_FIELD_LAYOUT_DESC"
menuitems="true"
extension="com_content"
view="article"
/>
or just hidden field for layout you want. And it will work.
First of all, you will need to do a template override. It's very easy. Documentation showing you how to do this can be viewed here:
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
You will then, in your override, need to use if statements based on what category ID the article belongs to. This can be achieved like so:
$catid = JRequest::getInt('catid');
if($catid == 1){
//layout for article belonging to a category with an ID of 1 goes here
}
elseif($catid == 2){
//layout for article belonging to a category with an ID of 2 goes here
}
else {
//standard layout goes here
}
Hope this helps.
The best way to achieve this is using K2 (http://getk2.org) as you can create sets of template overrides (eg. item, category etc.), then assign them to your categories in the back-end.
You can find a step-by-step guide here: http://getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
To make the switch easy they've also included a feature to import all your articles into K2.
This must in yourblog.xml in name="article" section
<fieldset name="article" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL">
I'm trying to make the Liferay (6.0.6) Asset Publisher publish all changes across multiple communities on the portal homepage. By clicking on a link the user is supposed to be redirected to another community and see the new web content. The problem is that the default behaviour of asset publisher (even with the hook to gather info from all communities) tries to get the url by searching the group of the current page (in which the content is not).
I decided to change the jsp showing the page to search all pages across all communities and find the first one containing the portlet with the desired web content. So
How could I get the portlet containing the web content by journal id of the web content?
How could I get the page containing the portlet?
Thanks
The PortletPreferences table in the database contains the configurations of each portlet in the system. The configuration of an articleId for a Web Content Display portlet is stored as a preference in this table. If you look at that table, there are 3 important columns:
plid contains the id of the Layout (=page) on which the portlet was dropped.
portletid contains the instance id of the portlet. For Web Content Display portlet, this ID has the format 56_INSTANCE_XXXX where XXXX is a unique hash.
preferences is an XML formatted string of all preferences and their values for this portlet.
An example of the preferences XML:
<portlet-preferences>
<preference><name>group-id</name><value>10139</value></preference>
<preference><name>article-id</name><value>14295</value></preference>
</portlet-preferences>
So it's just a question of getting your SQL queries right. As far as I know, there is no service you can call directly for this.
SELECT l.friendlyURL
FROM PortletPreferences p, Layout l
WHERE p.plid=l.plid
AND p.portletid LIKE '56_INSTANCE_%'
AND p.preferences LIKE '<preference><name>article-id</name><value>14295</value></preference>';
Something like the following allows you to find the Layout on which an article is Rendered.
List<Long> layoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds(groupId, false, articleId);
long layoutId = 0;
if (!layoutIds.isEmpty()) {
layoutId = layoutIds.get(0).longValue();
Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId);
String url = PortalUtil.getLayoutURL(layout, themeDisplay);
...
}
I'm trying to build a new navigation system based on myPlaces portlet. The aim is to show every page contained in each community/organization that can be accessed by the user.
I'm stuck on the Layout system. I retrieved the LayouSet of the community (both private and public), but I can't manage to retrieve the Layoust (which are actually the pages).
How can I do that? I hoped there would be simplye a getLayouts() from LayoutSet model, but there is nothing like it.
OK I got it, I had to go through LayoutLocalServiceUtil:
List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);