ThemeShaper Forums » Thematic

[closed]

Override Post's Content in Child Theme

(9 posts)
  • Started 2 years ago by bogh
  • Latest reply from helgatheviking
  • This topic is resolved
  1. bogh
    Member

    From what I see, in thematic/library/extensions/content-extensions.php, the following code adds the post's content, but again I can't figure out how to override it in my child theme, I have tried to replace "thematic_content" with "childtheme_override_content", but nothing happens...

    function thematic_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'	=> 'Permalink to ' . $post_title) );
    			if ( has_post_thumbnail() ) {
    				$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . 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);
    }

    Thank You

    Posted 2 years ago #
  2. bogh
    Member

    I have managed to override it. See below

    function childtheme_override_content_init() {
    		global $thematic_content_length;
    
    		$content = '';
    		$thematic_content_length = '';
    
    		if (is_home() || is_front_page()) {
    			$content = 'full';
    		} elseif (is_single()) {
    			$content = 'full';
    		} elseif (is_tag()) {
    			$content = 'excerpt';
    		} elseif (is_search()) {
    			$content = 'excerpt';
    		} elseif (is_category()) {
    			$content = 'excerpt';
    		} elseif (is_author()) {
    			$content = 'excerpt';
    		} elseif (is_archive()) {
    			$content = 'excerpt';
    		}
    
    		$thematic_content_length = apply_filters('thematic_content', $content);
    
    	}
    add_action('thematic_abovepost','childtheme_override_content_init');
    
    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'	=> 'Permalink to ' . $post_title) );
    			if ( has_post_thumbnail() ) {
    				$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . 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);
    }

    But now I would like to make it show that "Read More" link

    Basically I need to show a maximum of 200 characters in a post and then "... Read More", and it should be only on the Home Page, so please tell me if there is unneccesary code, before I add the is_home.

    Thank You

    Posted 2 years ago #
  3. did you change anything in the first function?

    so you need the home page excerpts to be different from the regular archive excerpts? or do you wish to change the style of excerpts everywhere?

    i think you need to filter thematic_post but i'll give an example after you follow up

    Posted 2 years ago #
  4. bogh
    Member

    Thank you again for you fast reply.

    I have tried to change some things on both functions, but what I have posted is the original code from thematic, with childtheme_override_, but I haven't got a good result.

    I would like to change only the content(except the post's header & footer, just the text) of the posts from the home page.

    So, on the home page's posts I want to show about 200 characters, and then "...Read More".

    I have done it somehow with the code above, but I think it can be made easier, I mean with less code and without ovewritting the thematic post's functions entirely.

    Posted 2 years ago #
  5. so you need 2 types of excerpts? i did that once... it' somewhere on the forum, i'll have to dig around alter.

    Posted 2 years ago #
  6. bogh
    Member

    Yes, I think I need 2 types of excerpts

    Posted 2 years ago #
  7. this will create a 2nd excerpt type called 'home_excerpt' by filtering the thematic_content filter. the second function will change what is posted by thematic_post() when displaying something in the style of the 'home_excerpt'

    right now it is almost identical to the regular excerpt except that each one will say "Bacon is delicious!" just before the excerpt. you should see this only on the home page and not on any other type of archive.

    function kia_home_excerts($content){
    	if (is_home() || is_front_page()) {
    		$content = 'home_excerpt';
    	}
    	return $content;
    }
    add_filter('thematic_content','kia_home_excerts');
    
    function kia_home_excert_type($post){
    	global $thematic_content_length;
    
    	if ( strtolower($thematic_content_length) == 'home_excerpt') {
    		$post = '';
    		$post .= 'Bacon is delicious! ' . 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'	=> 'Permalink to ' . $post_title) );
    			if ( has_post_thumbnail() ) {
    				$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    				}
    		}
    	} 
    
    	return $post;
    }
    add_filter('thematic_post','kia_home_excert_type');
    Posted 2 years ago #
  8. bogh
    Member

    Thank you, that is a nice one.
    I have modified it a bit, to shorten the text more and to add a Read More link.

    //Shorten Post Content on Home Page, and add a Read More link
    function ShortenPostContent($text) { // Function name ShortenText
    	$chars_limit = 200; // Character length
    	$chars_text = strlen($text);
    	$text = $text." ";
    	$text = substr($text,0,$chars_limit);
    	$text = substr($text,0,strrpos($text,' '));
    
    	if ($chars_text > $chars_limit)
    	   { $text = $text.'';
    	   $text .= '...<a href="';
    	   $text .= apply_filters('the_permalink', get_permalink());
    	   $text .= '" class="read_more_link">';
    	   $text .= __('Read More', 'thematic');
    	   $text .= '</a>';
    	   }
    	   return $text;
    }
    
    function home_excerpts($content){
    	if (is_home() || is_front_page()) {
    		$content = 'home_excerpt';
    	}
    	return $content;
    }
    add_filter('thematic_content','home_excerpts');
    
    function home_excerpt_type($post){
    	global $thematic_content_length;
    
    	if ( strtolower($thematic_content_length) == 'home_excerpt') {
    		$post = '';
    		$post .= ShortenPostContent(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'	=> 'Permalink to ' . $post_title) );
    			if ( has_post_thumbnail() ) {
    				$post = '<a class="entry-thumb" href="' . get_permalink() . '" title="Permalink to ' . get_the_title() . '" >' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '</a>' . $post;
    			}
    		}
    	}
    	return $post;
    }
    add_filter('thematic_post','home_excerpt_type');

    I don't know if it is the best way to add a read more link, but it looks good for me.

    Posted 2 years ago #
  9. you could've added the read more link in the home_except_type() function. but it is fine where it is too. the only reason i would change it would be if you needed to use the shortening function in places and NOT need a read more link... strictly just to shorten something. sounds like you can mark this one resolved.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.