skip to Main Content

On my project, I have this code and I need to add a link on a image popup using Fancybox

<?php if ($this->dados_globais['popup'] && $this->router->fetch_class() == "home") {                   
foreach ($this->dados_globais['popup'] as $popup) {
 if ($popup->imagem) {
      $img = base_url('./admin/assets/upload/popups/' . $popup->imagem);
      echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '"  data-caption="' . $popup->nome . '"></a>';

   } else {
      $link = $popup->link;
      echo '<a class="popup" data-fancybox="popups" href="' . $link . '"></a>';
            }
        }
    } ?>

Please advise so I can insert a link on an image.

2

Answers


  1. Chosen as BEST ANSWER

    i did this and it worked

    <?php if ($this->dados_globais['popup'] && $this->router->fetch_class() == "home") {
        foreach ($this->dados_globais['popup'] as $popup) {
            if ($popup->imagem) { ?>
                <script>
                    $(document).ready(function() {
                        var url = '<?php echo $popup->link_imagem ?>';
                        url = url.replace(/^https?:///i, '');
                        $('.fancybox-content').attr('data-url', url);
                        $('.fancybox-content').css('cursor', 'pointer');
                        $(".fancybox-content").click(function() {
                            var url = $(this).attr('data-url');
                            window.open('http://' + url, '_blank');
                            return false;
                        });
                    });
                </script>
    
                  <?php $img = base_url('./admin/assets/upload/popups/' . $popup->imagem);
                echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '"  data-caption="' . $popup->nome . '"></a>';
            } else {
                $link = $popup->link;
                echo '<a class="popup" data-fancybox="popups" href="' . $link . '"></a>';
            }
        }
    } ?>
    

        <script>
            $(document).ready(function() {
                $(".popup").fancybox({
                    'overlayShow': true
                });
    
                if ($(".popup").length) {
                    $(".popup:first").click();
                }
            });
        </script>


  2. You just have to figure out how to create link to thumbnail image and then place inside <a> element, smth like this:

    echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '"  data-caption="' . $popup->nome . '"><img src="' . $img . '" /></a>';
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search