ThemeShaper Forums » Thematic


Use post thumbnail as a link a post

(5 posts)
  • Started 4 years ago by bwaw
  • Latest reply from bwaw
  • This topic is not resolved
  1. I am working on a website and have created a childtheme using Thematic as the parent theme. I am relatively new to PHP but looking around and reading articles on especially this forum helped me a lot to get most things done.
    One thing however I can't seem to get working. I get (I think) the basic idea, but I just don't know how to implement it. I really could do with (some) help.

    This is what I would like to do. I have read about using post thumbnails on a parent page that link to a child page. However I would like to get the post thumbnails or featured images as they are now called I believe, to link to a single post.

    To give you a visual idea of what I want to achieve:

    I have been searching around the internet for code snippets I thought would be of use to me. Like parent-childpage thumbnail link. However I couldn't get it to work.

    I have enabled the post thumbnail support with the add_theme_support in the functions.php and assigned a 'feature image' to a test post.

    I have also created a page.php template (projects.php) based on the standard Thematic page template in my child theme folder. Apart from the definition at the top of the page they are identical.

    Help is more than welcome.

    Posted 4 years ago #
  2. you can wrap all thumbnails in a link to their post w/ the following (i've also wrapped it in a div too):

    //wrap thumbs in link to post
    function my_post_image_html( $html, $post_id, $post_image_id ) {
                  $html = '<div class="thumbnail"><a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html .  '<span class="linktopost">' . get_the_title($post_id) . '</span></a></div>';
                  return $html;
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    Posted 4 years ago #
  3. Thanks helgatheviking. I have pasted the code into my functions.php and inserted a php line with my_post_image_html (<?php my_post_image_html($html, $post_id, $post_image_id); ?> )into my projects.php page. I must be doing something wrong because nothing shows up.

    Slightly off topic. Could you tell me what the numbers 10 and 3 in the last line stand for. I am guessing the 10 stands for the number of posts that need to be displayed. As for the 3 I have no clue. As I wrote before... I am in the still (steep) learning curve.

    Posted 4 years ago #
  4. can't tell b/c i don't know myself. pretty much copied directly from:

    Posted 4 years ago #
  5. OK clear :-) I'll keep trying. Thanks again for your help.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.