- Posts: 54
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Item image in category view - add url to image ?
[SOLVED] Item image in category view - add url to image ?
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
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
-
- Offline
- Platinum Member
- Posts: 15920
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
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
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.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
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>
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
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
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
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
-
- Visitor
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
Please Log in or Create an account to join the conversation.
- Yiota
-
- Visitor
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
And yes i see the whole url when looking at the article, it goes like this: www.bonderomantikk.no (showing http:// also in front of the www - it was just stripped here in this answer )
But i also notice when i hover the image, it is not showing me the address to www.bonderomantikk.no, its showing me www.skilsmisse.net
I figure there is something not quite right in the php code, but i cannot see where and whats might be wrong.
Please Log in or Create an account to join the conversation.
- Yiota
-
- Visitor
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
I had the fields displayed in item view but not in category view.
But, then there is another issue; what do i add to open the link in a new window (not self) ?
And also, would it be possible to somehow hide the extrafields in the category view, cause it dont look any good.....
Please Log in or Create an account to join the conversation.
- Yiota
-
- Visitor
<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); ?>" target="_blank">
To hide the rest of the extra fields block you can either do it by commenting out its block of code in the category_item.php file or through css by adding to the class .catItemExtraFields a display:none;
Please Log in or Create an account to join the conversation.
- jeanette hustad
-
Topic Author
- Offline
- Senior Member
- Posts: 54
Thank you so much Yiota and Krikor for amazing help! And thanks for beeing so patient with me :-)
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Item image in category view - add url to image ?