Forums

[resolved] Attach permalink to image (6 posts)

  1. JacoGriesel
    Member
    Posted 2 years ago #

    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!

  2. JacoGriesel
    Member
    Posted 2 years ago #

    *sigh*

    Seems we're all a bunch of novices here... Searching for help... Mostly in vain...

  3. JacoGriesel
    Member
    Posted 2 years ago #

    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!

  4. JacoGriesel
    Member
    Posted 2 years ago #

    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!

  5. JacoGriesel
    Member
    Posted 2 years ago #

    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!

  6. jcaruso
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic