Actions

J1.5

Difference between revisions of "Make a Section Menu Item drill into a Category Blog layout"

From Joomla! Documentation

m
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{review}}
 
 
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.
 
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.
  
Line 30: Line 29:
  
 
Here are the steps:
 
Here are the steps:
# Make a copy of the rhuk_milkyway template as outlined in the following article: [[Tutorial:Create_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.
+
# 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.
 
# 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.
 
# In the Joomla! back end, navigate to Extensions → Template Manager. You should now see the new template in the list.
Line 40: Line 39:
  
 
===Add a parameter to the View===
 
===Add a parameter to the View===
 +
<blockquote>''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.''</blockquote>
  
 
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.
 
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.
Line 65: Line 65:
  
  
[[Category:Tips and tricks]]
+
[[Category:Archived version Joomla! 1.5]]
[[Category:Tips and tricks 1.5]]
+

Latest revision as of 10:58, 18 June 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

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:

  1. 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".
  2. Copy these three files from the folder <Joomla! home>/components/com_content/views/category/tmpl to the new folder created above:
    • blog.php
    • blog_item.php
    • blog_links.php.
  3. 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:

  1. 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.
  2. 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.
  3. In the Joomla! back end, navigate to Extensions → Template Manager. You should now see the new template in the list.
  4. Click on the new template. A screen will show that allows you to assign the template to Menu Items.
  5. 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.