Keyword

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 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
11 years 6 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

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 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
11 years 6 months ago - 11 years 6 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>

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 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
11 years 6 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.

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 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
11 years 6 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
11 years 6 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
11 years 6 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.

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 months ago - 11 years 6 months ago #121796 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
Its a required text field (not area) with no default value.
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
  • Yiota's Avatar
  • Visitor
11 years 6 months ago #121797 by Yiota
Check that you have the Extrafields enabled in this category listing.

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

  • jeanette hustad
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 months ago #121798 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
That was it!
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
  • Yiota's Avatar
  • Visitor
11 years 6 months ago #121799 by Yiota
To open the link in a new page you have to add to the <a> property a target="_blank" as follows
<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
  • jeanette hustad's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 6 months ago #121800 by jeanette hustad
Replied by jeanette hustad on topic Re: Item image in category view - add url to image ?
wow so pleased! :cheer:

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.


Powered by Kunena Forum