0

I have purchased a theme from magento2 marketplace , i have a code for images slider on my homepage , i wants to a define an anchor tag for one specific image like this <a><img> ...</a> so that i open a link on click of that image inside slider code , here's theme code looks like for slider :

 <?php $img= $_helperImage->init($_image['file'])->resize($width,$height); ?>
 <img
        <?php if($_parameters['lazyLoad'] && $i!=0): ?>
            src="<?php echo $img ?>" class="owl-lazy" data-src='<?php echo $_helperImage->init($_image['file'])->resize($width,$height); ?>'
        <?php else: ?>
            src='<?php echo $img; ?>'
        <?php endif; ?>

         <?php if ($_parameters['controlNavThumbs']): ?> data-hash="<?php echo $classid.$key ?>" <?php endif; ?> alt="<?php echo $_image['link'] ?>" title="<?php echo $_image['link'] ?>"

          />

and that's the location path of my specific image in which i want to define anchor tag :

echo $_helperImage->init($_firstImage['file']).'codazon/slideshow/cache/590x460/w/e/web_banner_11_a.png';

can anyone guide me please for making this condition , thanks!

EDITED : Following condition anchor tag is applying on all images:

 <?php $img = $_helperImage->init($_image['file'])->resize($width,$height); ?>
                            <?php $url = "https://127.0.0.1/site/pub/media/codazon/slideshow/cache/590x460/w/e/web_banner_11_a.png"; ?>
                            <?php if($url): ?>
                                <a target=”_blank” href="<?php echo "fb.com"; ?>">
                <?php endif; ?>
                            <img
                                <?php if($_parameters['lazyLoad'] && $i!=0): ?>
                                    src="<?php echo $img ?>" class="owl-lazy" data-src='<?php echo $_helperImage->init($_image['file'])->resize($width,$height); ?>'
                                <?php else: ?>
                                    src='<?php echo $img; ?>'
                                <?php endif; ?>
                                <?php if ($_parameters['controlNavThumbs']): ?> data-hash="<?php echo $classid.$key ?>" <?php endif; ?> alt="<?php echo $_image['link'] ?>" title="<?php echo $_image['link'] ?>"
                            />
                            <?php if($url): ?>
                                </a>
<?php endif; ?>
1

Create one more field in your slider module whose name will be url.

And then use the following code instead of yours:

<?php $img = $_helperImage->init($_image['file'])->resize($width,$height); ?>
<?php $url = "Put your code to get the url from database"; ?>
<?php if($url): 
    <a href="<?php echo $url; ?>">
<?php endif; ?>
<img 
    <?php if($_parameters['lazyLoad'] && $i!=0): ?>
        src="<?php echo $img ?>" class="owl-lazy" data-src='<?php echo $_helperImage->init($_image['file'])->resize($width,$height); ?>'
    <?php else: ?>
        src='<?php echo $img; ?>'
    <?php endif; ?>
    <?php if ($_parameters['controlNavThumbs']): ?> data-hash="<?php echo $classid.$key ?>" <?php endif; ?> alt="<?php echo $_image['link'] ?>" title="<?php echo $_image['link'] ?>"
/>
<?php if($url): 
    </a>
<?php endif; ?>

Hope this helps.

| improve this answer | |
  • Hi this anchor tag is applying on all images bro , please see my question section edit portion – Hamza Mustafa Apr 26 '18 at 9:14
  • Don't use the image url as $url. You need to add one field in your slider module and put fb.com as value only for those images you want to add anchor then it will be dynamic. – Sukumar Gorai Apr 26 '18 at 9:18
0

that worked for me .i just keep it simple .

 <?php $img = $_helperImage->init($_image['file'])->resize($width,$height); ?>
                            <?php $url = 'https://127.0.0.1/site/pub/media/codazon/slideshow/cache/590x460/w/e/web_banner_11_a.png' ; ?>

                            <?php if($img == $url ) { ?>
                                <a target=_blank href="<?php echo 'fb.com'; ?>"> <img src="<?php echo $url; ?>" />  </a>
                             <?php } else{  ?>
                        <?php $img = $_helperImage->init($_image['file'])->resize($width,$height); ?>
                                 <img src="<?php echo $img; ?>" />
                            <?php   }?>
| improve this answer | |

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.