toombeos
toombeos

Reputation: 93

Joomla: Override Category Blog output multiple times?

Yes. I want to override output of Category Blog component to 2 different display styles.

For first style, i copied and edited blog_item.php & blog.php in [mytemplate]/html folder. Then i choose template style from dropdown in backend of my category blog. That's worked. The display of category blog change as i expected.

But if i want to create another style and use in another category blog. How could i do ? And how to i named my files ( I tried blog_1.php, blog_item_1.php ) but only see my first style display in backend.

I'm using joomla 2.5.

Please help me. Thank you very much !

=================================================================================

[UPDATED] I solved this issue. Here my solution:

  1. Clone my template to [my_template_2]
  2. Go to [my_template_2]/html/com_content/category then edit blog.php, blog_item.php as my needs.
  3. Go to backend, at my category blog menuitem, i assigned [my_template_2] as its template style.

Then it worked. Both my category blog have its own style.

This maybe not very good solution because i have to use multiple templates, but at this time it's quite enough for me.

Thank you, stackoverflowers.

=================================================================================

[UPDATED 2]

Now, with multiple template styles, I could create unlimited styles for my category blog component within just only one template. That's very much better.

Upvotes: 2

Views: 4152

Answers (3)

tristanbailey
tristanbailey

Reputation: 4605

Based on the learnings above here is my code for the /templates/mytheme/com_content/category/blog.php

And then in the Global Configuration > Article Manager Options > Category choose Blog as the override/ layout.

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
$pageclass_sfx = trim($this->pageclass_sfx);

// so pick it on the page class in menu item
if (isset($pageclass_sfx) && $pageclass_sfx != '') {
    echo $this->loadTemplate($pageclass_sfx);
} else {
    echo $this->loadTemplate('default');
}

I can add multiple elseif if something else is needed, or it will look for 'blog_' . $this->pageclass_sfx . 'php'. It is always beginning blog_ as thats coded into the com_content. The old blog i moved to blog_default.php and blog_default_item.php

Upvotes: 1

Elin
Elin

Reputation: 6755

You don't need to use multiple styles. What you need is to use alternate layouts and alternative menu layouts. For alternative menu layouts in the html/componentname/category folder of your template make a new style with a unique set of names similar to the way blog already provides an alternative to category list in the article category layout folder. Also make a new xml file for each layout that you make, with a matching name.

When you create your menu item you will now get these alternatives along with your other normal choices. Just select the one you want.

Upvotes: 1

shakiba
shakiba

Reputation: 42

As you may know, joomla doesn't let developers make different styles for its components.

I think you have to list all menus which are made by "category blog component" in template managing page and let users set each menu style at there.** and at blog.php, check template setting and then load customized style...


** you have to develop a custom field element which list all "category blog component" menus.

* you can use this code to accessing template parameters in component's template :

$app        =& JFactory::getApplication();
$template   = $app->getTemplate(true);
$paramsTemplate = $template->params;
$style = $paramsTemplate->get('style');

Upvotes: 1

Related Questions