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:
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();
}
?>