1

Defining a Item in K2, we can upload an image in the Image tab of the K2 Item. Is it possible to create a link to that image? So when a user click in the image is redirect to the same link of the Title.

0

Yes, you can link the image of an article to the article itself. This is, actually, a default property of K2. If you are wanting to do this in a category listing, make sure you have the following code in the category_item.php file of your K2 template. K2 template files are typically stored in /templates/[YOUR-THEME]/html/com_k2/templates/default. If you've created an alternate K2 template, then default in the file path should be changed to your template name.

    <?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?>
    <!-- Item Image -->
    <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>
    <?php endif; ?>

This will check to see if the K2 category options are set to output the K2 item's image and make sure that one has been assigned. If so, it will output the image with a link to the article on that image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.