Hi Tom,
there's lots of tutorials out there already on it. I've used several of them on sites for clients. I actually did it just recently on one site (they wanted the "read more" link to expand further content, rather than go to the single post page). How that was done was...yep - I created my own function. In the index.php file, I used it in place of the_content:
<?php toggle_read_more('Read the rest of this entry »'); ?>
And the function looked like so:
function expand_header_js() {
global $post;
if(have_posts()) : while(have_posts()) : the_post();
$text = $post->post_content;
$find = strpos($text, '<!--more-->');
if($find !== false) {
$ids[] .= $post->ID;
}
$commentIDs[] .= $post->ID;
endwhile; endif; wp_reset_query;
$header = "\n" . '<!-- toggle read more -->' . "\n";
$header .= '<script type="text/javascript">' . "\n";
$header .= 'var $toggleReadMore = jQuery.noConflict();' . "\n";
$header .= '$toggleReadMore(document).ready(function() {' . "\n\n";
if(!empty($ids)) {
foreach($ids as $i) {
$header .= "\t" . '$toggleReadMore("#expand-content-' . $i . '").hide();' . "\n";
$header .= "\t" . '$toggleReadMore("#expand-link-' . $i . '").click(function() {' . "\n";
$header .= "\t\t" . '$toggleReadMore("#expand-content-' . $i . '").toggle("fast");' . "\n";
$header .= "\t\t" . '$toggleReadMore(this).text($toggleReadMore(this).text() == "Read the full article" ? "Hide the article" : "Read the full article");' . "\n";
$header .= "\t\t" . 'return false;' . "\n";
$header .= "\t" . '});' . "\n\n";
}
}
foreach($commentIDs as $c) {
$header .= "\t" . '$toggleReadMore("#comments_div-' . $c . '").hide();' . "\n";
$header .= "\t" . '$toggleReadMore("#expand-comment-link-' . $c . '").click(function() {' . "\n";
$header .= "\t\t" . '$toggleReadMore("#comments_div-' . $c . '").toggle("fast");' . "\n";
$header .= "\t\t" . '$toggleReadMore(this).text($toggleReadMore(this).text() == "Leave a Comment" ? "" : "Toggle Comment Form");' . "\n";
$header .= "\t\t" . 'return false;' . "\n";
$header .= "\t" . '});' . "\n\n";
}
$header .= '});' . "\n";
$header .= '</script>' . "\n";
$header .= '<!--/end toggle read more -->' . "\n\n";
echo $header;
}
function toggle_read_more($type = '') {
global $post;
$text = $post->post_content;
$id = $post->ID;
$find = strpos($text, '<!--more-->');
if($find !== false) {
$text = explode('<!--more-->', $text, 2);
$pretext = apply_filters('the_content', $text[0]);
$posttext = apply_filters('the_content', $text[1]);
$before = '<div id="expand-content-' . $id . '" class="expand-print">' . "\n";
$after = '<!-- end expandable -->' . "\n" . '</div>' . "\n\n";
$after .= '<a class="more-link" href="" id="expand-link-' . $id . '">Read the full article</a>' . "\n";
$content = $pretext . $before . $posttext . $after;
} else {
$content = apply_filters('the_content', $text);
}
if($type == 'return') return $content;
else echo $content;
}
and you had to have the jquery enqueued. The theme I did for this client is massive (seriously customized) so I *think* I have everything here for just this functionality, but I'm not 100% sure I didn't forget something! bu hope it gets you started, at least. :)