Make a Section Menu Item drill into a Category Blog layout
From Joomla! Documentation
The "J1.5" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
In Joomla! 1.5, a Section Layout Menu Item creates a list of Categories in the Section. When you drill into a Category, a Category List layout shows. In some situations, it is preferable to have a Category Blog layout show instead of a Category List layout. This article shows you a number of options to create a Section Layout that drills into a Category Blog layout.
We will discuss this in three parts.
In the first part, we'll see how to do this by overriding the rhuk_milkyway template. This is the easiest solution, but it means that you cannot use the Category List layout anywhere in the site.
In the second part, we'll see how we can create a copy of the rhuk_milkyway template so that we can still use the standard Category List layout on other pages in the site.
In the third part, we'll add an extra parameter to the 'Section Layout' menu option to be able to choose whether to display the Categories as a list (Category List layout) or in the blog format (Category Blog layout).
Override the rhuk_milkyway Template
A complete explanation of template overrides is available in the article How to override the output from the Joomla! core. Here are the steps for our example:
- Create a folder in <Joomla! home>/templates/rhuk_milkyway/html called "com_content". Create a folder under the new "com_content" folder called "category". So the whole thing will be "<Joomla! home>/templates/rhuk_milkyway/html/com_content/category".
- Copy these three files from the folder <Joomla! home>/components/com_content/views/category/tmpl to the new folder created above:
- Rename these three files, changing the word "blog" to "default", as follows:
- blog.php → default.php
- blog_item.php → default_item.php
- blog_links.php → default_links.php
Now, when you drill down from a Section List, you should see a Category Blog layout instead of a Category List layout. As with the normal Section List, you cannot directly set the parameters for the layout that shows after the drill down. However, the following article explains how you can do this using "hidden" Menu Items: How to control Category List layouts when drilling from a Section Layout. In our case, you would create hidden Category Blog Menu Items to control the parameters for the blogs that show in the drill downs.
Create a Copy of rhuk_milkyway
As mentioned earlier, there is an important side effect of the template override as done above. We will lose the ability to do Category List layouts anywhere in our site. If you don't need to use this type of layout, then the method above is fine. However, if you do want to use Category List layouts in other places in the site, then we need to use the slightly more complicated method discussed in this part.
One important feature of template overrides is that they only affect Menu Items that use a specific template. This is what makes them so flexible. In this case, we can create a second template that overrides the Category List layout to be a Category Blog layout. Since we still have our original template, Menu Items that use the original template will be unaffected by our override. So we can still use the Category List layout for Menu Items that use the original template.
Here are the steps:
- Make a copy of the rhuk_milkyway template as outlined in Creating a copy of the MilkyWay Template. Note that you don't need to follow the last three steps (zipping the files and so on) unless you want to distribute the template to other sites.
- Follow the instructions above to do the template override in the newly copied template (for example, "my_template"). If you have created the override files in the original template, delete them to restore the original behaviour for this template.
- In the Joomla! back end, navigate to Extensions → Template Manager. You should now see the new template in the list.
- Click on the new template. A screen will show that allows you to assign the template to Menu Items.
- Under the "Menu Assignment" section, click "Select from List" and select the Section layout that you wish to override.
- Note: If you have Category Blog or Category List Menu Items for the Categories in this Section, you will need to assign the new template to these Menu Items as well. This is because Joomla! will use the Itemid for a List or Blog layout for this Category when drilling down, and the template is determined by the Itemid.
At this point, the Section List Menu Item should drill down to the blog layout, but you should still be able to use Category List layouts for other Menu Items in the site. Note that you will not be able to use Category List layouts for the Categories in the Section List. But you can use Category List layouts for any other Categories.
Add a parameter to the View
Note: The following is a "core hack", meaning that one of the Joomla! core files is modified. This means that this file could get overwritten during a Joomla! upgrade. If you make this change, be sure to keep a backup of the modified file or of the modified code. That way you can re-apply this change if it gets overwritten.
You can avoid side effects of the previous methods by editing the php code and the parameters of your layout. This creates a neater, more intuitive set-up but the code will need to be re-implemented should there be a upgrade to Joomla! that overwrites the file.
Add a parameter in to the file \components\com_content\views\section\tmpl\default.xml (after the 'spacer' parameter seems a good place)
<param name="category_layout" type="list" default="list" label="Category Layout" description="PARAMSCATEGORYLAYOUT"> <option value="default">Default</option> <option value="blog">Blog Layout</option> </param>
Edit the code in \components\com_content\views\section\view.html.php. Look for the code:
$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');
and replace it by:
$layout = $params->get('category_layout') ; $category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout='.$layout);
Then you will have a new parameter in your menu that gives you the choice between default and blog layout for your categories in that section only.