ThemeShaper Forums » Thematic

[closed]

styling excerpted posts

(4 posts)
  • Started 3 years ago by kim4true
  • Latest reply from kim4true
  • This topic is resolved
  1. I am in the process of customizing a thematic child theme. I have successfully gotten most of what I want on the home page. See:

    http://debraclopton.com/w/

    Two issues:

    1. I want to limit the homepage to just one category. (books)
    2. I can't seem to get the excerpts styled correctly on the home page. I found some great help on this forum from Kathy Darling as you will see from my functions.php file, and this works on the excerpts that appear everywhere except the home page.

    Can someone tell me how to fix my homepage loop to apply the excerpt controls?

    <?php

    // Add support for thumbnails
    add_theme_support('post-thumbnails');
    set_post_thumbnail_size(100, 161, TRUE);
    add_image_size('homepage-thumbnail',200, 321, TRUE);

    // output a list of top-level pages
    function authorsite_footer_pagelinks() {
    echo '<ul id="simplepages">';
    wp_list_pages('depth=1&sort_column=menu_order&title_li=');
    echo '';
    }

    // Add Header Image
    function thematic_logo_image() {
    echo '<span id="header-image"></span>';
    }
    add_action('thematic_header','thematic_logo_image',6);

    /*-----------------------------------------------------------------------------------*/
    /* KIA TOTAL CONTROL OF EXCERPTS
    /* by Kathy Darling
    /* www.kathyisawesome.com (coming eventually)
    /*-----------------------------------------------------------------------------------*/

    //Replace wp_trim_excerpt with addition of filter for strip_tags
    function improved_trim_excerpt($text) {
    $raw_excerpt = $text;
    if ( '' == $text ) {
    $text = get_the_content('');

    $text = strip_shortcodes( $text );

    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);

    $tags = apply_filters('strip_tags', NULL);

    $text = strip_tags($text, $tags);
    $excerpt_length = apply_filters('excerpt_length', 55);
    $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if ( count($words) > $excerpt_length ) {
    array_pop($words);
    $text = implode(' ', $words);
    $text = $text . $excerpt_more;
    } else {
    $text = implode(' ', $words);
    }
    }
    return apply_filters('improved_trim_excerpt', $text, $raw_excerpt);
    }

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'improved_trim_excerpt');

    /* Class that enables excerpt length parameter */
    /* called via kia_excerpt('length') */

    class Excerpt {

    // Default length (by WordPress)
    public static $length = 55;

    // Default more (by WordPress)
    public static $more = '[...]';

    // Default tags (none)
    public static $tags = '';

    // So you can call: kia_excerpt('short');
    public static $types = array(
    'short' => 25,
    'regular' => 55,
    'long' => 80,
    'xlong' => 150,
    );

    // So you can call: kia_excerpt('short','ellipse');
    public static $more_types = array(
    'none' => '',
    'regular' => '[...]',
    'ellipse' => '...',
    );

    /**
    * Sets the length for the excerpt,
    * then it adds the WP filter
    * And automatically calls the_excerpt();
    *
    * @param string $new_length
    * @return void
    * @author Baylor Rae
    */
    public static function filter($new_length = 55, $new_more='[...]',$new_tags='') {
    Excerpt::$length = $new_length;
    Excerpt::$more = $new_more;

    Excerpt::$tags = $new_tags;

    add_filter('strip_tags', 'Excerpt::new_tags');
    add_filter('excerpt_length', 'Excerpt::new_length',98);
    add_filter('excerpt_more', 'Excerpt::new_more',99);

    return Excerpt::output();

    }

    // Tells WP the new length
    public static function new_length() {
    if( isset(Excerpt::$types[Excerpt::$length]) ){
    return Excerpt::$types[Excerpt::$length];
    } else {
    return Excerpt::$length;
    }
    }

    // Tells WP the new more
    public static function new_more() {

    if( isset(Excerpt::$more_types[Excerpt::$more]) ) {
    return Excerpt::$more_types[Excerpt::$more];
    } else {
    $db = new ReadMore(Excerpt::$more);
    return $db->readmore(Excerpt::$more);
    }
    }

    // Tells WP the new strip tags
    public static function new_tags() {
    return Excerpt::$tags;
    }

    // Echoes out the excerpt
    public static function output() {
    return get_the_excerpt();
    }

    }

    // An alias to the class
    function get_kia_excerpt($length = 55, $more='[...]', $tags='') {
    return Excerpt::filter($length, $more, $tags);
    }

    // An alias to the class
    function kia_excerpt($length = 55, $more='[...]', $tags='') {
    echo get_kia_excerpt($length, $more, $tags);
    }

    class ReadMore {
    private $text;

    public function __construct($text) {
    $temp = " ..." . ''._($text).'';
    $this->more = $temp;

    }
    public function readmore($text) {
    return $this->more;
    }
    }

    // Change default Thematic excerpts to kia_excerpts
    function childtheme_excerpts($post) {
    global $thematic_content_length;
    if ( strtolower($thematic_content_length) == 'excerpt' ) {
    $post = '';
    $post .= "<p>" . get_kia_excerpt('long','Read more','<p>') . "</p>";
    if ( apply_filters( 'thematic_post_thumbs', TRUE) ) {
    $post_title = get_the_title();
    $size = apply_filters( 'thematic_post_thumb_size' , array(200,200) );
    $attr = apply_filters( 'thematic_post_thumb_attr', array('title' => 'Links to ' . $post_title) );
    if ( has_post_thumbnail() ) {
    $post = '' . get_the_post_thumbnail(get_the_ID(), $size, $attr) . '' . $post;
    }
    }
    }
    return $post;
    }
    add_filter('thematic_post', 'childtheme_excerpts');

    // custom homepage loop
    function authorsite_indexloop() {
    query_posts("posts_per_page=4");
    $counter = 1;
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    <?php thematic_postheader();
    if ($counter == 1 && has_post_thumbnail() && !is_paged()) {
    the_post_thumbnail('');
    } ?>
    <div class="entry-content">
    <?php the_excerpt(); ?>
    " class="more"><?php echo more_text() ?>
    <?php $counter++; ?>
    </div>
    </div>
    <!-- .post -->
    <?php endwhile; else: ?>
    <h2>Oops!</h2>
    <p>Something is not working quite right here. Please contact us and let us know using the contact link you'll find in the top menu. Thank you!</p>
    <?php endif;
    wp_reset_query();
    }

    ?>

    Posted 3 years ago #
  2. O.K. I ditched all Kathy's beautiful excerpt styling code in favor of a nice plugin. See: http://wordpress.org/extend/plugins/advanced-excerpt/ - It's taking care of my needs nicely.

    Posted 3 years ago #
  3. but my code was so beautiful.

    the part you are missing (though i am relatively sure i discussed it in the original post) is how to switch the home page to use excerpts. also i swear i just wrote this in another thread yesterday.

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

    that's all you need to get some kind of excerpt going.

    additionally, i wrote all that code to give you the ability to make excerpts of different lengths. if you don't need it and the plugin does what you need, more power to ya.

    ps- you can put code between 2 backtick ` characters.

    Posted 3 years ago #
  4. Thanks Kathy. Sorry I didn't see your reply sooner. I am finally getting a clue about what I'm doing, but it's changed a bit as I've gone along.

    I also want to say thanks for all the help you, personally, provide on this forum. Every question I've hunted answers for has been answered best by you. :-)

    Now to the question at hand, I think the problem with the codes for the excerpts was ignorance on my part. I'm having difficulties stringing it all together. I understand what I read, I think, but when I try to implement it, I get stuck either not knowing where to put the code, or missing some small vital piece of the puzzle! That's the real reason I tend to opt for the plug-ins. In this case, there were a few more features built in that solved another problem or two.

    Now I'm going to go see your replies to my other couple of posts. I have more questions to ask but will do so with a fresh post - and watch more carefully for replies!

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.