Keyword

Display category image in K2 Content Module

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 10 months ago #120586 by Robert Peterson
Display category image in K2 Content Module was created by Robert Peterson
Hi, everyone! I'm using J!3.1.6, and I'd like to add the category image next to each entry in the K2 Content module.

I've tried this code to no avail:
<?php echo $item->category->image; ?>

This has to be an easy one, right? Every other K2 element is in there. All I need to do is yoink the category image associated with each item.

Thanks!!!!!

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 10 months ago #120587 by Yiota
I'm afraid that you cannot fetch the category image through the K2 content module without having to make modifications up to the extend of database queries to the core files.

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

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 10 months ago #120588 by Robert Peterson
Replied by Robert Peterson on topic Re: Display category image in K2 Content Module

Yiota Ziaggou wrote: I'm afraid that you cannot fetch the category image through the K2 content module without having to make modifications up to the extend of database queries to the core files.


Rats! OK, how about this:

Can the module sustain some basic logic related to the category? I'm thinking of something like this:
if category = 'Booga' {

// do something

} elseif category = 'Zooga' {

// do something

} else {

// do something

} endif

Is something like that possible?

Thanks!!!

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 10 months ago #120589 by Yiota
Yes you can do something like that in the module. Just use $item->categoryname for your category variable.

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

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 10 months ago #120590 by Robert Peterson
Replied by Robert Peterson on topic Re: Display category image in K2 Content Module

Yiota Ziaggou wrote: Yes you can do something like that in the module. Just use $item->categoryname for your category variable.


Yiota, thanks so much for the help! I've tried the following code, but it's throwing a syntax error. Sorry -- I must be missing something obvious.
<?php if $item->categoryname == 'AAA' {
    echo 'AAA is the Category'
} elseif $item->categoryname == 'BBB' {
    echo 'BBB is the Category'
} elseif $item->categoryname == 'CCC' {
    echo 'CCC is the category'
} endif; ?>

Any ideas?

Thank you again!!!

b

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

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 10 months ago #120591 by Robert Peterson
Replied by Robert Peterson on topic Re: Display category image in K2 Content Module
Wait -- I may have it figured out:
<?php if ( $item->categoryname == "AAA" ) {
                echo 'AAA is the Category';
            } elseif ( $item->categoryname == "BBB" ) {
                echo 'BBB is the Category';
            } elseif ( $item->categoryname == "CCC" ) {
                echo 'CCC is the category';
            }  ?>

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 10 months ago #120592 by Yiota
Yes, this should work in your module code.

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


Powered by Kunena Forum