Forums

Featured Image Post Link (19 posts)

  1. 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.

  2. Jarret Cade
    Member
    Posted 1 year ago #

    Which theme are you using?

  3. mrittman
    Member
    Posted 1 year ago #

    It's a theme I created.

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    try it with this:

    <?php
    if ( has_post_thumbnail()) {
      echo '<a href="' . get_permalink() . '" >' . the_post_thumbnail() .'</a>';
    }
    ?>
  5. 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' );

  6. 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

  7. keesiemeijer
    moderator
    Posted 1 year ago #

    try it with this (in the loop):

    <?php
    if ( has_post_thumbnail()) {
      echo '<a href="' . get_permalink($post->ID) . '" >';
      the_post_thumbnail();
      echo '</a>';
    }
    ?>
  8. 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.

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    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.

  10. mrittman
    Member
    Posted 1 year ago #

    Thanks Rev. Voodoo! I didn't even think about that. I just might do it!

  11. 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...

  12. keesiemeijer
    moderator
    Posted 1 year ago #

    No need, I added it to the Codex. I also added code for thumbnails linking to large image size

  13. Jarret Cade
    Member
    Posted 1 year ago #

    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 :)

  14. Jarret Cade
    Member
    Posted 1 year ago #

    Heh, good work keesiemeijer :D

  15. mrittman
    Member
    Posted 1 year ago #

    Awesome! Thanks for adding this!

  16. keesiemeijer
    moderator
    Posted 1 year ago #

    you're welcome. It was the first time I added to the Codex.

  17. mrittman
    Member
    Posted 1 year ago #

    Great. Now I know I can do the same if I ever need to.

  18. riepa
    Member
    Posted 5 months ago #

    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?

  19. keesiemeijer
    moderator
    Posted 5 months ago #

    @riepa
    What theme are you using? On what page do you want to do this? The front page?

Topic Closed

This topic has been closed to new replies.

About this Topic