Keyword

[SOLVED] Item image in category view - add url to image ?

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 10 months ago #121786 by jeanette hustad
Hi,

I have a category view listing. When clicking on the image or title, the article itselves is opening.
But what i want is when clicking on the image and title (at least the image), a custom url should be opened and not the article itselves.

Is this possible, and can anyone guide me how to do it ?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121787 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Item image in category view - add url to image ?
Hello Jeanette.

This can be done with extrafields. The best approach would be to set the link as as an extrafield (text field and not link ) and then in your template (category_item.php) you need to replace the href="" attribute with that extrafield.

For rendering specific extrafields use this snippet: getk2.org/community/New-to-K2-Ask-here-first/171284-Where-to-edit-K2-after-Item-Fields

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

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #121788 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
Hi Krikor,
and thanks so much for getting back to me.
I have created an extrafield called "webadresse" and assosiated it to the correct category.

But i must admit my php skills could be better, so i hope you can guide me a bit more. I think that i have to edit this section in the category_item.php file, but i dont know what to add/remove. Can you help?
 <div class="catItemImageBlock">
                  <span class="catItemImage">
                    <a href="<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
                        <img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
                    </a>
                  </span>
                  <div class="clr"></div>
          </div>

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

More
10 years 9 months ago - 10 years 9 months ago #121789 by Lefteris
Let's start with a small but important detail. Your extrafield should be a simple textfield type and not a link type. The link type constructs the whole <a> element and it is hard to contain the image in it.
So, what I need you to do is to change the extrafield's type to textfield and make sure that you involve the http:// part in your link.
Then, if the extrafield alias is "webadresse", as well, you can replace the above code block with this one
<div class="catItemImageBlock">
                  <span class="catItemImage">
                    <a href="<?php echo $this->item->extraFields->webadresse->value; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
                        <img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
                    </a>
                  </span>
                  <div class="clr"></div>
          </div>

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

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #121790 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
The extrafield is of type text, and i have implemented the php.
But seems it is just sending me to the frontpage of my site.....

Have a look:
www.skilsmisse.net/dating-tjenester.html

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121791 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Item image in category view - add url to image ?
Make sure the extrafield is both set and correct. Some characters can be stripped upon saving and it is case sensitive. Finally make sure you are using K2's latest version.

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

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #121792 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
Yes the extrafield is set for all articles in this category.

Example: article "Bonderomantikk.no" has its extrafield "webadresse" set to www.bonderomantikk.no but it still goes to the frontpage of the site.
And I have the latest K2 version, just updated yesterday. Joomla 2.5.16

Category_item.php is changed like this:
	 <div class="catItemImageBlock">
                  <span class="catItemImage">
                    <a href="<?php echo $this->item->extraFields->webadresse->value; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
                        <img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
                    </a>
                  </span>
                  <div class="clr"></div>
          </div>

Any ideas whats going wrong ?

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 9 months ago #121793 by Yiota
Make sure that the alias of the extra field is the one we have used in the code, webadresse.

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
10 years 9 months ago #121794 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
The NAME is Webadresse with a capital W and the ALIAS is webadresse without any capital, so that should be correct.

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 9 months ago #121795 by Yiota
Is your extra field textfield or textarea. When you see this specific item through the backend do you see the whole url?

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


Powered by Kunena Forum