ThemeShaper Forums » Thematic

hooking into the_excerpt

(4 posts)
  • Started 5 years ago by talino
  • Latest reply from talino
  • This topic is resolved
  1. Relatively new to Thematic and child-themes, so please excuse me if all of this sounds silly.

    I would like to get the_excerpt_reloaded plugin to handle my excerpts, so that they don't get stripped of link and image tags. This should happen in category, archives and search pages. Since there is no filter hook for the thematic_content section in charge of this, the only way I could accomplish that was to get rid of the default actions for the loops, like this:

    function mytheme_overrides() {
    	remove_action('thematic_categoryloop', 'thematic_category_loop');
    	remove_action('thematic_archiveloop', 'thematic_archive_loop');
    	remove_action('thematic_searchloop', 'thematic_search_loop');
    }
    add_action('init', 'mytheme_overrides');

    Then rewrite the loops, like this:

    function mytheme_category_loop() {
    while (have_posts()) : the_post(); ?>
    
    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
       <?php thematic_postheader(); ?>
    <div class="entry-content">
    <?php mytheme_content(); ?>
    
    				</div>
    				<?php thematic_postfooter(); ?>
    			</div><!-- .post -->
    
    		<?php endwhile;
    }
    add_action('thematic_categoryloop', 'mytheme_category_loop');

    All the above is needed only in order to call mytheme_content instead of thematic_content (it's the only change in the code). This function is repeated two more times for the archives and search loops. Then, I need to change one line in thematic_content for it to become mytheme_content, like this:

    function mytheme_content() {
    
    	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';
    	}
    
    	$content = apply_filters('thematic_content', $content);
    
    	if ( strtolower($content) == 'full' ) {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    	} elseif ( strtolower($content) == 'excerpt') {
    		$post = get_the_excerpt_reloaded(100, '<img><a><h2><h3><h4><strong>', 'excerpt', TRUE, '(Read more)', FALSE, 1, TRUE, 'span', 'more', TRUE);
    	} elseif ( strtolower($content) == 'none') {
    	} else {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    	}
    	echo apply_filters('thematic_post', $post);
    }
    </strong></a>

    Seems like an awful lot of work, and is a case where modifying the theme directly would have resulted in one line of code being changed. Is there a shorter way (currently) of doing all this in a Thematic child theme?

    BTW, I know I could write one function for all three but I want to keep future customizations of each of the three loops possible.

    Thanks.

    Posted 5 years ago #
  2. 1. After looking through the thematic source, the loop stuff could probably stand to get some TLC sometime in the near future. There just aren't enough action hooks to do any serious swapping. But then again, for most people, the Thematic loop logic is probably sufficient in its default form.

    2. With that said, Thematic does offer a handy strategic filter that will be perfect for you situation (I think):

    add_filter('thematic_post', 'mytheme_post');
    function mytheme_post($post) {
    	if(is_archive()) {
    		$post = get_the_excerpt_reloaded(100, '<img><a><h2><h3><h4><strong>', 'excerpt', TRUE, '(Read more)', FALSE, 1, TRUE, 'span', 'more', TRUE);
    	}
    	return $post;
    }

    Should work, unless there is some Thematic-specific exception that I'm not aware of.

    Posted 5 years ago #
  3. m8nkey
    Member

    Thanks Nathan,

    Your solution worked for me.

    Posted 5 years ago #
  4. Obviously, you're right. Much more elegant and less bug-prone. Thanks a lot, Nathan.

    Posted 5 years ago #

RSS feed for this topic

Reply

You must log in to post.