Support Forum

  • Page:
  • 1

How to get this order in a k2 category template

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

Hi there,

I am looking for ideas how to code the following k2 category template.

I want to show

a) the main category
b) a subcategory
c) items of the subcategory
d) then another subcategory with items

I know how the category.php loops through. It is this code here.

<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
<!-- Subcategories -->
<div class="k2SubCategories">


<?php foreach($this->subCategories as $key=>$subCategory): ?>


What I want to do here is to check for e.g. a category alias or an category id. In case it is matching I want to call a different template for the subcategory and the items, display it and keep on looping for the second subcategory.

I have this code here which is for the category_item.php call.

<?php foreach($this->leading as $key=>$item): ?>
<?php
// Load category_item.php by default
$this->item=$item;
if($item->categoryalias == 'example') {
echo $this->loadTemplate('example')
} else {
echo $this->loadTemplate('item');
}
?>
<?php endforeach; ?>

I know that I have to do some hefty code changes to move the primary, secondary items into the subcategory listing.

However, my problem is even prior to that, as I cannot get the check for a particular subcategory id or alias to work.

Any suggestion, any link to a tutorial or idea for coding is appreciated.

thanks and best regards
  • MaMuster's Avatar
  • MaMuster
  • LIfetime Developer - Big Bamboo
  • 329 posts
  • 10 Thanks
  • Karma: 4
The administrator has disabled public write access.
I forgot to add - it would be great if I could check for a category alias and then call items with one particular tag.

A site setup would be a product and all articels ever published with the tag related to the product. But once again I first need to figure our the right php for the id or alias check.
  • MaMuster's Avatar
  • MaMuster
  • LIfetime Developer - Big Bamboo
  • 329 posts
  • 10 Thanks
  • Karma: 4
The administrator has disabled public write access.
Hi there,

The code snippet looks right in theory. I dont know of any off the top of my head with this but I tend to just do a lot of trial and error for this sort of stuff.

I would start by checking your $item->categoryalias is actually working because that seems to be the key part of the process.

The other thing I would do in this case is print_r($item); Just to see what the $item contains. From the look of it the code should be working but I guess its just trial and error trying to match the right conditions.

Let us know what you find.

Anthony
  • Anthony Olsen's Avatar
  • Anthony Olsen
  • LIfetime Developer - Big Bamboo
  • 23925 posts
  • 788 Thanks
  • Karma: 433
The administrator has disabled public write access.

zentoolsIf you use Zentools please post a review at the Joomla! Extensions Directory.

Happy Campers