mrittman
Member
Posted 1 year ago #
Well I'm tearing my hair out over such a simple issue. How the hell do you link the featured image to the post url!? There's not ONE tutorial online about how to do this!!? I just want the stupid featured image to link to the post it's associated with. If anyone can help, I would be really happy.
Thanks.
Which theme are you using?
mrittman
Member
Posted 1 year ago #
try it with this:
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink() . '" >' . the_post_thumbnail() .'</a>';
}
?>
mrittman
Member
Posted 1 year ago #
Thank you but that did not seem to work...
And I have this in my functions.php file:
add_theme_support( 'post-thumbnails' );
mrittman
Member
Posted 1 year ago #
Here is my page. It looks like it's putting a link after the <img> tag instead of before it...
http://www.votechrisbrooks.com/news
try it with this (in the loop):
<?php
if ( has_post_thumbnail()) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail();
echo '</a>';
}
?>
mrittman
Member
Posted 1 year ago #
That worked perfect keesiemeijer :)
One question though...why is this not in the documentation? I figured a common task like this would be referenced. And it seems like a lot of code to just add a link to the featured image. I mean, it's not a crazy amount but you'd think it'd be a simple parameter to add. Your code should be on this page somewhere:
Function Reference - the post thumbnail
Thanks again man, I really appreciated it.
http://go.rvoodoo.com/Wpthumb
Is awriteup I did about linking thumbnails to posts....
One way is a function, another to simply wrap the thumbnail in a link
As for documentation, if you think the documentation is lacking, feel free to add to it! The Codex is written by volunteers.
mrittman
Member
Posted 1 year ago #
Thanks Rev. Voodoo! I didn't even think about that. I just might do it!
mrittman
Member
Posted 1 year ago #
Rev. Voodoo, you might want to check your code on your blog... I get a parse error using your version...
No need, I added it to the Codex. I also added code for thumbnails linking to large image size
mrittman, the Codex page that you linked to in your earlier responses does in fact have the code you were looking for.
If you visit http://codex.wordpress.org/Function_Reference/the_post_thumbnail and scroll down to the Linking to the Post Permalink headline you'll find the code :)
Heh, good work keesiemeijer :D
mrittman
Member
Posted 1 year ago #
Awesome! Thanks for adding this!
you're welcome. It was the first time I added to the Codex.
mrittman
Member
Posted 1 year ago #
Great. Now I know I can do the same if I ever need to.
keesiemeijer, I came across the same problem and I can't solve it by myself. Unfortunatelly I'm using a template which doesn't have loop.php - do you know where shoud I put your code instead?
@riepa
What theme are you using? On what page do you want to do this? The front page?