ThemeShaper Forums » Thematic

[closed]

Post Thumbnail with Permalink

(9 posts)
  • Started 12 years ago by cannobbio
  • Latest reply from melomanda
  • This topic is not resolved
  1. cannobbio
    Member

    How do I wrap the post thumbnail with a permalink?
    Im using this function:

    
    // Add post thumbnail support in WP2.9
    if ( function_exists( 'add_theme_support' ) )
    add_theme_support( 'post-thumbnails' );
    
    // Add post thumbnail to post excerpt
    function my_post_title($title) {
    	if (is_home() || is_archive() || is_search()) {
    		return get_the_post_thumbnail(NULL, 'thumbnail', array('class' => 'alignleft')) . $title;
    	}
    	else {
    		return $title;
    	}
    }
    add_filter('thematic_postheader_posttitle', 'my_post_title');
    

    Thank you!

    Posted 12 years ago #
  2. hi cannobblo,

    This worked for me, maybe you can adapt it to what you need?

    // ads to each thumbnail a link to the permalink
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    	$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '" rel="nofollow">' . $html . '</a>';
    	return $html;
    }
    function thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr)
    {
      $attachment =& get_post($post_thumbnail_id);
    
      // post_title => image title
      // post_excerpt => image caption
      // post_content => image description
    
      if ($attachment->post_excerpt || $attachment->post_content) {
        $html .= '<p class="thumbcaption">';
        if ($attachment->post_excerpt) {
          $html .= '<span class="captitle">'.$attachment->post_excerpt.'</span> ';
        }
        $html .= $attachment->post_content.'</p>';
      }
    
    	return $html;
    };
    add_action('post_thumbnail_html', 'thumbnail_caption', null, 5);
    Posted 12 years ago #
  3. cannobbio
    Member

    Thank you lastraw!
    Will try your code tonight.
    Had a busy week, sorry for the late reply.

    cya

    Posted 12 years ago #
  4. this is even easier now w/ the featured image that started in WP 2.9

    add_theme_support( 'post-thumbnails' );
    
    //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 . '</a></div>';
    	return $html;
    }
    
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

    that wraps the thumbnails w/ the permalink... and to use it you just need to put the_post_thumbnail( 'thumbnail' ) into the excerpt

    // excerpt read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	if ( has_post_thumbnail() ) {
    		$child_excerpt =  the_post_thumbnail( 'thumbnail' ) . '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	else {
    		$child_excerpt = '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	return $child_excerpt;
     }
    
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    my function does a couple other things, but hopefully you get the idea

    Posted 12 years ago #
  5. Yea! Finally found the code to wrap a thumb with the permalink! Thanks.

    Posted 12 years ago #
  6. "Continue Reading"

    Is there a away to set a custom field and so that a custom anchor text to be used instead of "Continue Reading", for SEO reasons? Thanks.

    Posted 12 years ago #
  7. kwight
    Member

    You can use get_post_meta to set a variable with the post's custom field, and insert that into your function: http://codex.wordpress.org/Function_Reference/get_post_meta

    Posted 12 years ago #
  8. you could also do something like

    $child_excerpt = '<p>' . $post_excerpt . '</p>' . '<p class="readmore">ID) . '">' . 'Continue Reading ' . get_the_title() .'</p>';

    and it would always come back

    "Continue Reading A Post About Bacon"
    "Continue Reading About Why Helga is Awesome"

    etc. :) but i think you could also do what kwight suggested w/ the custom fields. i never use custom fields though as i use WPAlchemy to create custom meta boxes instead. farinspace.com/wpalchemy-metabox/

    and don't the thumbnails come wrapped in a permalink by default these days? can't remember

    Posted 12 years ago #
  9. melomanda
    Member

    Hi! I try to make a gallery like post and I need that the thumbnail links to the full size image for displaying with Fancybox. Sorry I'm a not an expert with the code.

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.