1
votes

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?

4

4 Answers

1
votes

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.

0
votes

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.

0
votes

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.

0
votes

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

    <fieldset name="article" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL">