1

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?

thednp
  • 4,401
  • 4
  • 33
  • 45

4 Answers4

1

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.

Kintar
  • 11
  • 2
  • Can you please elaborate this answer? I have two different article layouts. I have two XMLs in my /html/com_content/article folder. However, adding your code to my blog.xml (in my category override folder). But the dropdown that appears in the "Choose a Layout" only shows default. – Vik Oct 09 '14 at 09:04
  • problem in your case - is that joomla componentlayout field finds only layouts without a corresponding xml, because layouts with corresponding xml is a menu items for joomla - not a layouts (well, i do not know why, but they have that explanation in field declaration comments). So, in your case i would recommend to create another category xml, in which you can have article_layout hidden field. That should work. – Kintar Oct 10 '14 at 09:22
0

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.

Lodder
  • 19,758
  • 10
  • 59
  • 100
  • Thanks for your input as well, I think this is a much better approach. However, my idea is to connect the category layout with their articles layout, one way could be to make use of the page class feature, looks more promising if I would combine with your code here. EG: if category page has class "blog", the article should use the layout blog. Your way is too rigid, it needs to be more specific and flexible. Thanks again. – thednp Feb 26 '13 at 13:45
0

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.

Adam B
  • 1,140
  • 2
  • 18
  • 30
  • Thanks for your input. However, my work is to completely go ahead doing better than K2, just with the com_content. I got in trouble much with the K2 system and upgrading/migrating/porting is much o a pain. – thednp Feb 26 '13 at 13:42
0

This must in yourblog.xml in name="article" section

    <fieldset name="article" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL">
Max Sychov
  • 21
  • 1