6

I have created an override for my news category (which works perfectly) and another article override for my news articles as follows

// Category Override
my_template/html/com_content/category/news.php
my_template/html/com_content/category/news_item.php
my_template/html/com_content/category/news_children.php
my_template/html/com_content/category/news_links.php

// Article Override    
my_template/html/com_content/article/news.php

My question is : How can I (automatically) apply the above Article Override (news.php) to all the articles under the news category without doing it manually for each article via "Article Edit Options" or globally via "Article Manager Options".

enter image description here

  • Do you mean to override the category view or the article view or both? – COBIZ webdevelopment Jun 8 '15 at 14:37
  • @cobiz-webdevelopment I created a single article override (html/com_content/article/news.php) and I want to apply it to all the articles in a specific category. – Taimur Aziz Jun 9 '15 at 10:02
3
  1. Go to Content -> Category Manager
  2. Edit your category
  3. Go to Options tab
  4. Assign your layout in "Alternative Layout" option.
  • 1
    So you need to keep your default.php and default_xxxx.php's as well in your override. – COBIZ webdevelopment Jun 8 '15 at 12:01
  • @nagarjun This will apply the override on the "Blog List View" only. I was asking about the "Single Article View" .. How can I assign an article override to all the articles under my a specific category when they viewed as single article. – Taimur Aziz Jun 8 '15 at 12:14
  • You can't assign single article override to category and their by all articles in the category. The flow is other way. You apply layout to category and all articles under it will derive the layout from category layout override. – Nagarjun Jun 8 '15 at 13:45
  • @Nagarjun There's no way to assign a single article override from the category options. Can you clarify more from where I can do that. – Taimur Aziz Jun 8 '15 at 17:53
3

I don't think you can do that automatically within Joomla itself.

I would just create a new layout (set as default one globally) which checks the category id of the loaded article and then decides if it loads the default or the news layout.

A bit hackish and hardcoded but should work.

3

For an article override for items only of a specific category,
I guess you could do something like this in /your_template/html/com_content/article/default.php

if ($this->catid==2) {
    $this->loadTemplate('news');
} else {
    $this->loadTemplate('original');
}

I did not test this, but you get the picture I hope.

2

Just a little update on this : since Joomla 3.8, one can directly choose the Layout in the Menu Item > Articles > Blog

That menu item has to be Published of course, but it can be Hidden (also an option in the Menu item). And all the articles of the chosen Category will have the assigned Layout.

Cool !

1

If you can live with a single menu item being attached to every article, then use the menu item to apply either a new template or a new style.

0

I had similar problem and I achieved desired results by slightly altering one workaround already mentioned here.

In /my_template/html/com_content/article/ I have files default.php, default_default.php and default_altered.php. The default.php only decides which one of the other files loads. I tested two ways to do it.

Based on category id:

if ($this->item->catid==19) {
  echo $this->loadTemplate('altered');
} else {
  echo $this->loadTemplate('default');
}

Or based on active menu item id:

$menuid = JFactory::getApplication()->getMenu()->getActive()->id;
if ($menuid==107) {
  echo $this->loadTemplate('altered');
} else {
  echo $this->loadTemplate('default');
}

I don't know whether it is an ideal solution (I'm just learning it myself), but it worked for me. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.