• I have a function that works:

    <a href="<?php the_permalink() ?>" onmouseover="return tooltip('<img src=&quot;http://www.website.com/image.jpg&quot; /><');">

    And I need to replace ‘http://www.website.com/image.jpg‘ with the URL of the thumbnail.

    I just can’t figure out how to place the ‘get_the_post_thumbnail‘ or ‘get_post_thumbnail_id‘ into the string so it replaces the image URL with that of the thumbnail.

    This is part of my efforts to create a tooltip hover that, when you hover over the post link, it displays a thumbnail.

    Right now, I’m using Skinnytip Tooltips as the base. Any help is appreciated.

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter zerogravitydesign

    (@zerogravitydesign)

    I also tried this (which is what I want in theory, but failed miserably, most likely because of my syntax):

    <a href="<?php the_permalink() ?>" onmouseover="return tooltip(<?php $imgs = get_the_post_thumbnail($post->ID);
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $imgs, $matches);
    $img = $matches [1] [0];
    echo 'return tooltip(<<img src=&quot;' . $img . '&quot; /><);';?>);">
    Thread Starter zerogravitydesign

    (@zerogravitydesign)

    Okay, I’ve worked out a few things…

    This is working with adding in a specific image:

    <a href="<?php the_permalink() ?>"
    <?php
    print ("onmouseover=\"return tooltip('<img src=&quot;");
    print ("http://www.website.com/image.jpg");
    print ("&quot;/>');\"")
    ?>
    onmouseout="return hideTip();">

    Now, I need to replace that image with the thumbnail of a post. I’ve tried the following, but it doesn’t work:

    <a href="<?php the_permalink() ?>"
    <?php
    $thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post->ID ), 'full' ) ;
    print ("onmouseover=\"return tooltip('<img src=&quot;" . $thumbnail . "&quot;/>');\"")
    ?>
    onmouseout="return hideTip();">

    Any ideas? (I feel like I”m just talking to myself here…)

    Thread Starter zerogravitydesign

    (@zerogravitydesign)

    Got it working, here is the final code:

    1.) Install ‘SkinnyTip Tooltips’ plugin
    2.) Make sure thumbnails are in use on the current theme:
    add_theme_support( 'post-thumbnails' );
    3.) Add the following code inside my Loop:

    <a href="<?php the_permalink() ?>"
    <?php
    $thumbnail = wp_get_attachment_image_src ( get_post_thumbnail_id ( $post->ID ), 'full' ) ;
    print ("onmouseover=\"return tooltip('<img src=&quot;" . $thumbnail[0] . "&quot;/>');\"")
    ?>
    onmouseout="return hideTip();" onClick="return false;">

    Now, when I hover over my link, a tool tip that has the post thumbnail in it follows the mouse on rollover.

    I don’t understand you at all…

    1. I’ve installed ‘SkinnyTip Tooltips’ plugin.
    2. Thumbnails are in use.
    3. What is your Loop?.. Do you just mean code box? Or does Loop actually stand for something in particularly significant?

    Do you mind elaborating on how to install it properly? I’ve spent hours trying to get images into tooltips and it’s driving me insane.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need Help inserting a post thumbnail into a javascript function’ is closed to new replies.