Re: Excerpts
fel64 is right. So I made a change.
<?php
// from wp_trim_excerpt() in WordPress 2.3.1 formatting.php, just removed few lines
function make_excerpt($text) { // Fakes an excerpt if needed
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 55;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
return $text;
}
if ( $topics ) :
$last_post_ids = array();
foreach ( $topics as $topic )
$last_post_ids[] = $topic->topic_last_post_id;
global $bbdb;
$post_ids = $bbdb->get_col( "SELECT post_id, post_text FROM $bbdb->posts WHERE post_id IN (" . implode(',', $last_post_ids) . ")");
$post_texts = $bbdb->get_col( null, 1 );
$post_excerpts = array();
foreach($post_ids as $idx => $post_id)
$post_excerpts[$post_id] = make_excerpt( $post_texts[$idx] );
endif;
?>
<?php if ( $topics ) : foreach ( $topics as $topic ) : ?>
<tr<?php topic_class(); ?>>
<td><?php bb_topic_labels(); ?> <a href="<?php topic_link(); ?>"><?php topic_title(); ?></a>
<?php echo $post_excerpts[$topic->topic_last_post_id]; ?>
</td>
<td class="num"><?php topic_posts(); ?></td>
<td class="num"><?php topic_last_poster(); ?></td>
<td class="num"><small><?php topic_time(); ?></small></td>
</tr>
<?php endforeach; endif; // $topics ?>
On my test forum, 15 posts, without excerpts takes .119 sec, with excerpts takes .127 sec. Previous code takes .140 sec.