ThemeShaper Forums » Thematic

[closed]

Custom Excerpts

(10 posts)
  • Started 4 years ago by kbkisan
  • Latest reply from kbkisan
  • This topic is resolved
  1. kbkisan
    Member

    Hi there,

    I have been looking over the forum and can't seem to figure out how solve a problem I'm having with the excerpt (maybe because I'm no PHP expert :)

    Ok here's my story..

    On my site I want the homepage (I've put a static page as a homepage) to display what is put into the MANUAL EXCERPT box and ignore the FULL CONTENT or AUTO EXCERPT.

    And on my Category pages I want to show only an AUTO EXCERPT, and ignore the MANUAL EXCERPT and the FULL CONTENT.

    Is there any Thematic Wizard out there that can help me.

    Posted 4 years ago #
  2. Hi kbkisan,

    Thematic uses the thematic_content() to determine which pages get the "full content" or "auto-excerpts" Thematic uses the WordPress function get_the_content for "full content" and it uses the WordPress function get_the_excerpt to provide Thematic's "auto-excerpts".

    Thematic provides a filter to customize this behavior by using conditional tags. Category archiives get excerpts by default so we need to set the home page not to use the full post but the excerpt instead

    Here's a sample for you to try on for size:

    function child_content($content) {
    	if ( is_home() ) {
    		$content = 'excerpt';
    	}
    return $content;
    }
    add_filter('thematic_content', 'child_content');

    I realize that this may not seem to be the answer that you were looking for but I think it is the best solution given our options here. You'll have to manually create an excerpt for every post to get the "excerpt" behavior you desire.

    This may help to clarify how this behavior really is hinged to how WordPress handles it's various types of excerpts...
    From the Codex:

    The manual WordPress excerpt is often confused with the automatic excerpt or with the teaser (the part of a post that appears on the front page when you use the More tag). While both are related to the manual excerpt, they are different from it.

    The relationship between the three is this: When a post has no manual excerpt, WordPress looks for a teaser to use as excerpt. If the post has no teaser either, WordPress generates automatically an excerpt by selecting the first 55 words of the post.

    I hope that helps
    -Gene

    Posted 4 years ago #
  3. kbkisan
    Member

    Hi Gene and thank you so much for your answer.

    What I have managed to do now is use your function to be able to use the excerpt on the homepage like so:

    function child_content($content) {
    	if ( is_category() ) {
    		$content = 'excerpt';
    	}
    return $content;
    }
    add_filter('thematic_content', 'child_content');

    This takes care of my homepage..

    What I have so far for the Category page is this.

    // Add filter to the_content
    	add_filter('the_content', 'my_excerpts');
    
    function my_excerpts($content = false) {
    
    // If is the category page
    	if(is_category()) :
    		global $post;
    			$content = $post->post_content;
    			$excerpt_length = 15;
    			$words = explode(' ', $content, $excerpt_length + 1);
    			if(count($words) > $excerpt_length) :
    				array_pop($words);
    				array_push($words, '...');
    				$content = implode(' ', $words);
    			endif;
    			$content = '' . $content . '
    ';
    	endif;
    	return $content;
    }

    It kind of works.. But in my category page to get the code above to work I call the content with

    <?php echo (the_content()); ?>

    And that displays the image in the post as well. Is there a way to filter out the image somehow ? The thing is that I don't want the images from the post to appear.

    Best regards,
    Fannar

    Posted 4 years ago #
  4. Hi Fannar,

    as far as I understood your code you need to change your first function to:

    function child_content($content) {
    	if ( is_category() ) {
    		$content = 'full';
    	}
    return $content;
    }
    add_filter('thematic_content', 'child_content');

    Otherwise your excerpt filter won't work for a category page.

    Chris

    Posted 4 years ago #
  5. kbkisan
    Member

    Hi Chris,

    You're totally right on that one, but the problem I have when I use the

    <?php the_content ?>

    on my category page it obviously gets the images from that post just like it is supposed to :) but in my case I would like to filter out the images from the post, so It only shows the content text and no the image, but I'm not sure if that is possible, and I certainly don't know how to do it.

    Would it be possible to filter out the images from a the_content query ?

    Thanks,
    Fannar

    Posted 4 years ago #
  6. kbkisan
    Member

    I've managed to do it in the end with CSS, so I think I'll just leave it like that for now :) Thanks again for your help Gene and Chris, its not the first time you help me out when in trouble !

    Cheers,
    Fannar

    Posted 4 years ago #
  7. Let me check this tomorrow. Do you need just the plain text for your excerpt, or do you want to keep certain html tags?

    I have both filters somewhere on my machine. Used these for a heavily customized version of wp-o-matic.

    Chris

    Posted 4 years ago #
  8. kbkisan
    Member

    Thank you so much. I won't be needing any special formating, just the traditional .entry-content style. I really appreciate you taking the time to dig this up for me, because I prefer to do it in the function file instead of mixing it through css.

    Cheers,
    Fannar

    Posted 4 years ago #
  9. Hi Fannar,

    this is the important part taken from Thematic's helpers.php:

    $text = strip_shortcodes( $text );
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    	        $text = str_replace('"', '\'', $text);

    Chris

    Posted 4 years ago #
  10. kbkisan
    Member

    Thank you Chris ! This should do it :)

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.