• Resolved jacogriesel

    (@jacogriesel)


    Hey!

    I’ve borrowed a piece of code from the Hamahsaki theme to extract the first image in a post and show it as a thumbnail on the frontpage. The code follows:

    <div class="featcat" id="post-<?php the_ID(); ?>">
    <?php $id =$post->ID;
    $the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
    $pattern = '!<img.*?src="(.*?)"!';
    preg_match_all($pattern, $the_content, $matches);
    $image_src = $matches['1'][0]; ?>
    
    <div id="featcatpic" style="width: 40px; height: 40px;background: url(<?php if($image_src != '') { echo $image_src; } else { ?><?php bloginfo('template_directory'); ?>/images/default125.png<?php } ?>) 0 0 no-repeat;">
    </div>

    Now I would like to “attach” the permalink for the post to the image displayed. Any help?

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jacogriesel

    (@jacogriesel)

    *sigh*

    Seems we’re all a bunch of novices here… Searching for help… Mostly in vain…

    Thread Starter jacogriesel

    (@jacogriesel)

    Whoop-whoop!

    Our American friends must be up and going by now – maybe they can solve this for me…

    Any help would be appreciated…

    THANKS!

    Thread Starter jacogriesel

    (@jacogriesel)

    Four hours later and guess what?

    I SOLVED IT MYSELF!

    Lots of googling, lots of trial and error, lots of crappy parse messages, but eventually –

    I SOLVED IT MYSELF!

    In case anybody was struggling with the same problem –

    SOLVE IT YOURSELF!

    Thread Starter jacogriesel

    (@jacogriesel)

    OK, no need to be an arse…

    Here’s my solution in case somebody could use it.

    Replace:

    <div id="featcatpic" style="width: 40px; height: 40px;background: url(<?php if($image_src != '') { echo $image_src; } else { ?><?php bloginfo('template_directory'); ?>/images/default125.png<?php } ?>) 0 0 no-repeat;">
    </div>

    with:

    <div>
    <?php if ($image_src) { ?>
    <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $image_src; ?>" alt="Post Pic" width="200" height="200" /></a>
    <?php } else { ?>
    <a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php bloginfo('template_url'); ?>/images/default250.png" alt="Screenshot" width="200" height="200" /></a>
    <?php } ?></div>

    Easy!

    Hey dude!

    EVEN SIMPLER!

    <div class=”new-thumbnail”>
    ” rel=”bookmark”>
    <?php the_post_thumbnail( $size, $attr ); ?>

    Seriously, I searched and searched and found NOTHING!!!!

    This works though.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Attach permalink to image’ is closed to new replies.