Attach permalink to image
-
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)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Attach permalink to image’ is closed to new replies.