ThemeShaper Forums » Thematic

[closed]

thematic_content change thumbnail link

(7 posts)
  • Started 11 years ago by ki11ua2
  • Latest reply from ki11ua2
  • This topic is not resolved
  1. ki11ua2
    Member

    I'm trying to change the link of the thumbnail for the default thematic_content latest posts loop.
    What I want is the thumb to open in lightbox at the original size.
    I'm trying with variations of the following code, but does'n seem to ovverride it.

    function custom_content($content) {
    if ( strtolower($thematic_content_length) == 'excerpt') {
    if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    if ( has_post_thumbnail() ) {
    $post = '' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '' . $post;
    }
    }
    }
    }
    add_filter('thematic_content', 'custom_content');

    Any ideas?

    Thank you

    Posted 11 years ago #
  2. i think you're attacking the wrong filter... if you look at the function thematic_content() in header-extensions.php you'll see

    echo apply_filters('thematic_post', $post);

    so the filter to target is actually called thematic_post. idk why they did it that way. i banged my head into the wall over it for a long time. but the important thing to take away from it is that the filter name does not always match the function name. the filter name is the first parameter in the apply_filters statement.

    oh and you will need to RETURN something. otherwise you don't actually pass info to the filter.

    then you should be able to do something like

    function kia_lightbox_thumbs($post){
    	if ( strtolower($thematic_content_length) == 'excerpt') {
    				$post = '';
    				if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    					$post_title = get_the_title();
    					$size = apply_filters( 'thematic_post_thumb_size' , array(100,100) );
    					$attr = apply_filters( 'thematic_post_thumb_attr', array('title'	=> 'Permalink to ' . $post_title) );
    					if ( has_post_thumbnail() ) {
    						$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    						$post = '<a class="entry-thumb" class="lightbox" href="' . $image[0] . '" title="Permalink to ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    						}
    				}
    			}
    	return $post;
    	}
    	$post = '' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '';
    }
    add_filter('thematic_content', 'kia_lightbox_thumbs');

    you almost surely have to add some kind of class="lightbox" (depending on what plugin you're using) to the link. and the link src needs to point to the full size image, which is what i am doing with wp_get_attachment_image_src() function.

    untested, so there could be typos. note, you didn't put the excerpt in yours so i left it out. this will only show the thumbnail with no fallback if there isn't a thumbnail.

    Posted 11 years ago #
  3. ki11ua2
    Member

    Thanks for the reply,

    The solution was to add the following in my custom function file:

    function childtheme_override_content() {
    		global $thematic_content_length;
    
    		if ( strtolower($thematic_content_length) == 'full' ) {
    			$post = get_the_content(more_text());
    			$post = apply_filters('the_content', $post);
    			$post = str_replace(']]>', ']]>', $post);
    		} elseif ( strtolower($thematic_content_length) == 'excerpt') {
    			$post = '';
    			$post .= get_the_excerpt();
    			$post = apply_filters('the_excerpt',$post);
    			if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    				$post_title = get_the_title();
    				$size = apply_filters( 'thematic_post_thumb_size' , array(100,100) );
    				$attr = apply_filters( 'thematic_post_thumb_attr', array('title'	=> 'Image of ' . $post_title) );
    					if ( has_post_thumbnail() ) {
    						$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    						$post = '<a class="entry-thumb" class="thickbox" href="' . $image[0] . '" title="Image of ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    						}
    			}
    		} elseif ( strtolower($thematic_content_length) == 'none') {
    		} else {
    			$post = get_the_content(more_text());
    			$post = apply_filters('the_content', $post);
    			$post = str_replace(']]>', ']]>', $post);
    		}
    		echo apply_filters('thematic_post', $post);
    
    } // end content

    The solution was inspired by the current post & this: http://forums.themeshaper.com/topic/changing-content-of-excerpt-conditionally-and-editing-all-loops-at-once

    Your post again

    So double thanks

    Posted 11 years ago #
  4. you shouldn't need to override the whole thing if you are only changing part. that's the point of filters. did mine not work? i might have forgotten to
    global $thematic_content_length;

    Posted 11 years ago #
  5. ki11ua2
    Member

    This worked:

    //To enable post thumbnails
    add_theme_support( 'post-thumbnails' );
    
    function list_thickbox_thumbs($post){
    	global $thematic_content_length;
    	if ( strtolower($thematic_content_length) == 'excerpt') {
    					$post = '';
    					$post .= get_the_excerpt();
    					$post = apply_filters('the_excerpt',$post);
    					if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    						$post_title = get_the_title();
    						$size = apply_filters( 'thematic_post_thumb_size' , array(120,120) );
    						$attr = apply_filters( 'thematic_post_thumb_attr', array('title'	=> ' ' . $post_title) );
    							if ( has_post_thumbnail() ) {
    								$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    								$post = '<a class="entry-thumb" class="thickbox" href="' . $image[0] . '" title=" ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    								}
    					}
    	return $post;
    	}
    	$post = '' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '';
    }
    add_filter('thematic_post', 'list_thickbox_thumbs');

    Thank you

    Posted 11 years ago #
  6. that doesn't mess up your full page posts? b/c you aren't returning any value for them, nor returning the unaltered version. thematic already enables post_thumbnails so you don't need that i don't think. trimmed down.

    function list_thickbox_thumbs($post){
    	global $thematic_content_length;
    	if ( strtolower($thematic_content_length) == 'excerpt') {
    					$post = '';
    							if ( has_post_thumbnail() ) {
    								$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    								$post = '<a class="entry-thumb" class="thickbox" href="' . $image[0] . '" title=" ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('title'	=> ' ' . $post_title)) . '</a>' . $post;
    								}
    					}
    	return $post;
    }
    add_filter('thematic_post', 'list_thickbox_thumbs');
    Posted 11 years ago #
  7. ki11ua2
    Member

    You're right!
    Thank you

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.