WordPress.org

Support

Support » Plugins and Hacks » Link to post images in template with custom function

Link to post images in template with custom function

  • jrelgin
    Member

    @jrelgin

    I am trying to use a link in a page template to display the images from a post with a lightbox. I have added the following code to my functions.php:

    function portfolio_thumbnail_url($pid){
            $image_id = get_post_thumbnail_id($pid);
            $image_url = wp_get_attachment_image_src($image_id,'screen-shot');
            return  '$image_url[0]';
        }

    In my page template the link looks like this:

    <a title="<?=$title?>: <?=$desc?>" rel="lightbox[work]" href="<?php print portfolio_thumbnail_url($post->ID) ?>"><?php the_post_thumbnail('project-thumb'); ?></a>

    The results right now seem to be only showing one of my two post images and it shows it twice. I’ve been racking my brain on this for a while and any help would be appreciated. It could be the lightbox plugin I’m using (lightbox plus) but I am thinking it is an error in the function I have.

Viewing 2 replies - 1 through 2 (of 2 total)
  • jrelgin
    Member

    @jrelgin

    Well, I did find out that it was the lightbox plugin. I still haven’t been able to fix it, but I looked in inspector and found that all of the images were loading. I can’t believe I didn’t do that before!

    Anyway, if anyone is really familiar with lightbox or jquery, I could still use a nudge in the right direction.

    jrelgin
    Member

    @jrelgin

    UPDATE: I have to retract the statement about the problem being the lightbox.

    The function I have written above is nesting anchor links within anchor links which is not valid HTML. I still have a problem with the function.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Link to post images in template with custom function’ is closed to new replies.