Keyword

Get K2 item category in my template?

  • Janko Tomsic
  • Janko Tomsic's Avatar Topic Author
  • Offline
  • New Member
More
11 years 11 months ago #106066 by Janko Tomsic
Get K2 item category in my template? was created by Janko Tomsic
Hi all,

I have one question to ask;
I would like to get k2 category for opened item in my template so I can assign different modules to different categories. I cannot find a working solution so I'm asking for some help here form you k2 experts on this forum.

So I would need something like this; $k2catid = JRequest::getInt('id'); ... but this one returns item id instead id category that this item is in it.

Thank you for all your help in advance, much appreciated!

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

More
11 years 11 months ago #106067 by Gregwh
Replied by Gregwh on topic Re: Get K2 item category in my template?

Janko wrote: Hi all,

I have one question to ask;
I would like to get k2 category for opened item in my template so I can assign different modules to different categories. I cannot find a working solution so I'm asking for some help here form you k2 experts on this forum.

So I would need something like this; $k2catid = JRequest::getInt('id'); ... but this one returns item id instead id category that this item is in it.

Thank you for all your help in advance, much appreciated!


Not sure what you are trying to EXACTLY do but I did what you are asking for in the normal K2. What you do is go to the MENU you made up within a category and assign the CATEGORY to that menu under CATEGORY SETTINGS. So, anything then posted into that category goes in that area under that menu only.

For example, on www.sell-my-books.com I made up a top level menu called BOOKS and under that genres for people to post books online. If the author level user goes into that category and posts something, they actually have to tell the system to post within a particular category and when they do the posting appears ONLY there if I limit one category for one menu. If I chose to have 2 categories show up under one menu, I can then add that category to that menu in the menu settings in the Menu Manager.

That sounds like what you meant you wanted to do to me. Is it?

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

  • Janko Tomsic
  • Janko Tomsic's Avatar Topic Author
  • Offline
  • New Member
More
11 years 11 months ago #106068 by Janko Tomsic
Replied by Janko Tomsic on topic Re: Get K2 item category in my template?
Hi, thnx but that is not at all what I needed.

I'm viewing an item and I need to get that item's category ID in my template file. I need it as a php variable.
Like with this: $k2 = JRequest::getInt('id'); but with that call I get viewed item ID, but I would need to get it's category ID. So I would be able to display module positions in my template file based on K2 categories.

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

More
11 years 11 months ago #106069 by Gregwh
Replied by Gregwh on topic Re: Get K2 item category in my template?

Janko wrote: Hi, thnx but that is not at all what I needed.

I'm viewing an item and I need to get that item's category ID in my template file. I need it as a php variable.
Like with this: $k2 = JRequest::getInt('id'); but with that call I get viewed item ID, but I would need to get it's category ID. So I would be able to display module positions in my template file based on K2 categories.


You might do better asking that in a programming area under the Joomla forums. I am sure someone there would know how.

Greg.

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

  • Janko Tomsic
  • Janko Tomsic's Avatar Topic Author
  • Offline
  • New Member
More
11 years 11 months ago #106070 by Janko Tomsic
Replied by Janko Tomsic on topic Re: Get K2 item category in my template?
Will do that thank you.
I thought I should ask here first since it is a K2 forum after all ;)

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

More
11 years 11 months ago #106071 by Gregwh
Replied by Gregwh on topic Re: Get K2 item category in my template?

Janko wrote: Will do that thank you.
I thought I should ask here first since it is a K2 forum after all ;)


I understand what you mean but the only support you will get at K2 itself is from other K2 users, not the K2 people themselves. Sorry to say but that means for you it is a waste of time asking here as it is less likely that someone who is a K2 user on a site, like myself, knows the level of programming you are after. Really, there is no support from the K2 people at all. Never seen it before and I have been around k2 for a year though only using it for a few months. Relatively easy to get going but needs a lot of dressing up.

Greg.

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

More
11 years 10 months ago #106072 by Lefteris
Replied by Lefteris on topic Re: Get K2 item category in my template?
@Janko

You need to query the database to get the item category id:
<?php
$K2Itemid = JRequest::getInt('id');
if($K2Itemid)
{
$db = JFactory::getDBO();
$db->setQuery("SELECT catid FROM #__k2_items WHERE id = ".$K2Itemid );
$K2Catid = $db->loadResult(); 
}
?>

Note that this will only work in K2 item view pages.

@Greg
Really you haven't see any post by me for a whole year?

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

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

More
11 years 10 months ago #106073 by Gregwh
Replied by Gregwh on topic Re: Get K2 item category in my template?

Lefteris Kavadas wrote: @Janko

You need to query the database to get the item category id:

<?php
$K2Itemid = JRequest::getInt('id');
if($K2Itemid)
{
$db = JFactory::getDBO();
$db->setQuery("SELECT catid FROM #__k2_items WHERE id = ".$K2Itemid );
$K2Catid = $db->loadResult(); 
}
?>

Note that this will only work in K2 item view pages.

@Greg
Really you haven't see any post by me for a whole year?


When I was brand new to K2, I came here and asked for help. The only help I ever got - and thankfully it was my answer - was from another user and there were a lot of posts complaining about the lack of help from the K2 team and not to be surprised. I think I even posted "You cant complain about the help when there IS none!" in one message. No response from anyone.

Help from the K2 team didnt exist for ages so I went away and I figured it out for myself by doing a "Fargo" (from the TV show Eureka) and pressing every button to see what happened. That was the only thing that helped after that help from a user here. So I feel I am correct in saying the K2 team help here is pitiful at best but to be honest, I dont know what else is going on in your life. I had a heart attack a week ago today so that knocked me out of helping while I was in the thick of it for a few days last week. You may have a whole lot worse than that going on in your offline life so I have to be fair and say that if you can only post here every year then I cannot complain.

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

More
11 years 10 months ago #106074 by Kelsey Brookes
Replied by Kelsey Brookes on topic Re: Get K2 item category in my template?
Hi Greg,

I've been critical of the K2 team in the past too, but for what it's worth it's been great around here for a while now. Lefteris in particular is incredible - he's all over every thread and is genuinely helpful and knowledgable about every aspect of K2.

It's worth giving it another shot.

K

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


Powered by Kunena Forum