• Hi,
    I would like to link the thumbnail to the post link. Here is my site http://thisweekin.net/malibu/ and as you can see you can’t click on the thumbnail to go into the post.

    I have this code to show the thumbnail:
    <?php the_post_thumbnail(array(300, 9999), array('class' => 'alignleft post_thumbnail', 'alt' => 'alttext', 'title' => 'titletext', 'align' => 'left', 'hspace'=>10)); ?>

    I tried to add <a href="<?php the_permalink() ?>"> before it and close the <a> after but it doesn’ work.

    I appreciate any helps.

    Thanks

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter jumust

    (@jumust)

    Hey Curtiss thanks very much it did the job, the problem was not because of the align…sorry for the confusion..

    Also I tried to get the alt text of the thumbnail I set up in the post, but didn’t work this below, any thoughts?

    $alttext = array('alt' => trim(strip_tags( $attachment->post_excerpt )),);
    
    and than
    
    alt="<?php echo($alttext); ?>"

    Thanks for all

    The “post_excerpt” property of an attachment is the information you entered in the “Caption” section of the form. Is that what you really want? In order to retrieve the “alt” attribute, you will need to query for it. That query would look like:

    $alttext = get_post_meta( $img_id, '_wp_attachment_image_alt', true );

    Then, you can use:
    alt="<?php echo $alttext; ?>"

    However, if you want to use the “Caption” as the “alt” attribute, as you have shown above, that’s fine. The issue with the code you showed above is the fact that you are storing the information in an array, then trying to echo that array (which will usually just add “Array” to your code). In order to use the code you have above, you would need to change that “alt” part to:
    alt="<?php echo $alttext['alt']; ?>"

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Thumbnail links to post permalink’ is closed to new replies.