?
Solved

Joomla 2.5 alternate layouts for category

Posted on 2013-06-28
6
Medium Priority
?
1,437 Views
Last Modified: 2013-07-13
I'm a competent PHP programmer, but fairly new to Joomla and its voodoo ways.

I have a category named "tuesday-archive".  I have a series of old newsletter pages, each of which is an article belonging to that category.  I also have a module (type "Articles Category") which generates a list of all articles belonging to the tuesday-archive category.  I have an article (call it the "list" page) which renders that module.  My menu item points to the list page, which is assigned to a different category.

The overwhelming majority of these old newsletters came with their own full-page HTML, so displaying them in my site's current template is inappropriate.  I need to display them in a "blank" template.  I created an alternate layout by creating a very simple template file and saving it as /templates/mytemplate/html/com_content/category/news-archive.php.  The content is extremely basic:
<html>
  <head>
    <jdoc:include type="head" />
    <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/mytemplate/css/template.css" type="text/css" />
  </head>
  <body>
    <jdoc:include type="component" />
  </body>
</html>

Open in new window


When I go the category "tuesday-archive" in the category manager, under "Basic Options", I can see news-archive as a selectable option in the Alternate Layout drop-down.  It is selected, but browsing to one of the newsletter articles continues to use the full template for the site.  

In my research, I've found that the alternate layout assignment at the category level will not be applied if a menu item pointing to the category exists.  That is not the case here - the menu item is pointed at the list page, which is assigned to a different category.  Still, if I assign the alternate layout to that menu item instead of the category, then the destination list page, and all the archived articles, will use the alternate layout as directed.  This would be great, except the list page does need the normal site template.

What do I need to do to assign an alternate layout to any article belonging to a specific category, and be able to arrive there from normal menu navigation?
0
Comment
Question by:Steve Bink
  • 2
3 Comments
 
LVL 27

Assisted Solution

by:lenamtl
lenamtl earned 150 total points
ID: 39305196
Hi,

The old way was to create another template and assign it to the categories.

You can use layout overrides but seems not to work all the time depending of the template. I guess you have already read those pages but just in case:

http://docs.joomla.org/Layout_Overrides_in_Joomla_2.5
http://www.ostraining.com/blog/joomla/alternative-layouts-for-modules/

A possible solution:
http://irislines.com/blog/puzzled-by-alternative-layouts-not-working.html

*Suggestion when something is not working in Joomla I always switch to Joomla  default template and make my tests, some of free or premium templates have different code or miss some Joomla code.

Maybe an extension already exist and does what you need, you can check this link:
http://extensions.joomla.org/extensions/news-display/articles-display/latest-news
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 0 total points
ID: 39306695
I have read the doc page, and the ostraining.com procedure is essentially what I did to create my alternate layout.  In this case, I copied the primary site template and just removed everything.  The code I posted above is literally all there was in the file.   We are trying to avoid using overrides as a matter of policy.

It looks very much like I got caught up in the problem described in the irislines.com post.  In this case, the alternate layout showed up and was selectable in the category manager, but it would not apply.  My menu link was to an article which loads a module showing all the posts in the category - I was hoping the abstraction would make a difference.  In any case, the layout will not apply unless it is also applied to the menu item, and the menu item article cannot use the alternate layout.

What I eventually ended up doing is copying the main site template again.  Instead of removing everything, I inserted PHP logic to determine if the request is for the listing or a specific article.  If it is the listing, the normal template is used, otherwise, the stripped template it used.  I applied this alternate layout to the menu item, and it is working as desired.
<html>
  <head>
    <jdoc:include type="head" />
  </head>
  <body>
    <?php 
      /* if the URL includes 'tuesday-transit-news-archive', this is an actual news 
          archive article.
          Many of them come with full-page HTML included, so they are rendered 
          outside of the template.
          If 'tuesday-transit-news-archive' does not appear, this is probably the 
          listing page, which requires the template.  
          The template below is an exact copy of the site's default template.
      */
      if (strpos($this->base,'tuesday-transit-news-archive')===false) { ?>
       <!-- the site's default template - HTML, <jdoc />, etc -->
     <?php } else { ?>
       <jdoc:include type="component" style="xhtml" />
     <?php } ?>
  </body>
</html>

Open in new window

0
 
LVL 51

Author Closing Comment

by:Steve Bink
ID: 39323052
I engineered my own solution.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question