Keyword

Retrieve items from subcategory using category.php

  • David Turner
  • David Turner's Avatar Topic Author
  • Offline
  • New Member
More
11 years 5 months ago - 11 years 5 months ago #113064 by David Turner
hi,

i'm trying to add some code to the category.php file inside the template folder of com_k2.

i have a category page displaying two subcategories. i would like to be able to click on the subcategories and go straight into the first item in that category rather than to the category view which is the default link.

i plan on having each of the subcategories as galleries and when i click on a 'gallery' i go through to the first item in that gallery (or subcategory)

i'm thinking i need to write some php inside category.php that retrieves the items from the current subcategory. i can then isolate one of the items and wrap that link around the subcategories on the page.

hope that makes sense. anyone any ideas?

example:

go to this page: walksandwildlife.co.uk/galleries/

click a subcategory (or 'gallery')

then bypass this page: walksandwildlife.co.uk/galleries/gallery-1

and go straight to this page: walksandwildlife.co.uk/galleries/gallery-1/item/288-image-1

many thanks

dave

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 4 months ago #113065 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Retrieve items from subcategory using category.php
Hello Dave,

Inside category.php you will see the loops for each set of the items (leading, primary secondary).

You can duplicate a loop but edit it to output only the first item using the $key variable and the category id.
Then you can either get the template parts you want from category_item.php and change $this->item to $item
and use the link with a static text bellow the subcategory image.

You can also use a simple JS script if you are more familiar with JS. Just locate the first article of the subcategory (by using classes on category_item.php maybe) and c/p it's attributes to the subcategory link.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum