Alternative layout for article based on category i

2019-05-13 06:52发布

I currently have 2 'layouts' for articles in my Joomla 2.5 install

default.php
default_links.php
feature_link.php
feature_link.php

which work as intended when each is selected in the 'Edit Article' screen of the 'Article Manager' under 'Alternative Layouts'.

However, I'd like articles in a certain category to automatically display using one layout, and all other articles to display using the other.

I see you can select 'Alternative Layout' under the 'Category Manager', but this specifies the layout in 'Category' view of 'com_content' (as opposed to the layout of the articles WITHIN that category).

I've also taken a look through the 'Article Options' available as parameters when creating a 'Category Blog' menu item, however frustratingly you can't override or specify 'Alternative Layout' here - which would seem like the most obvious place.

TL;DR; - can I configure Joomla to set article-level layout based on the category of that article ?

1条回答
唯我独甜
2楼-- · 2019-05-13 07:05

Well thats a good question. Maybe you could make your default layout some kind of a switch: Put the regular layout in something like regular.php and the special in like special.php and have the default.php discover which category the article belongs to. Then include the code of the respective layout file... Just an idea.

Like this...

default.php:

<?php 
   ...
   $specialCategory = 42; // the id of your special category
   if($this->item->catid == $specialCategory){
       include "special.php";
   }else{
       include "regular.php";
   }
?>

Please note that I did not try so far...

Edit: I just found this in the com_users login view:

default.php

if ($this->user->get('guest')):
// The user is not logged in.
echo $this->loadTemplate('login');
else:
// The user is already logged in.
echo $this->loadTemplate('logout');
endif;

The files in the tmp folder are named default.php, default_login.php and default_logout.php.

查看更多
登录 后发表回答