Using Excerpts

From Habari Project

Jump to: navigation, search

By default, the k2 theme will "summarize" all posts. This is controlled via the theme.php file in the theme directory. The three parameters in the default code are 'more', 100, 1. 'more' is the text you want on the page to link to the full post, 100 is the number of characters, and 1 is the number of paragraphs. Which ever the function sees first (either 100 characters, or 1 paragraph), it will invoke the 'more' link. So if you want longer excerpts, you would change that to something like 500, 3, or what ever you were comfortable with. Conversely, you can drop the number of characters and paragraphs in function, and simply manually add inside the post.

Note, there may be formatting issues with custom themes

The first, is to simply comment out the line in your theme.php file that applies the summarize function to the posts. Line 23 of k2's theme.php file reads:

Format::apply_with_hook_params( 'more', 'post_content_out', 'more', 100, 1 );

Simply change that to:

// Format::apply_with_hook_params( 'more', 'post_content_out', 'more', 100, 1 );

Commenting out versus removing would be best, if for no other reason than it would make it easier to add back later. Now all of your posts should be full posts, not the truncated "excerpts".

A second, and more versatile method of using this function, would be to change how the summarize function is applied, there by giving you both excerpts, and full post output. It might be best to make a backup of this file before making changes, just in case you make any errors, or decide to revert to the default file.

In line 23 in the above example, we simply commented out the entire thing. Now we are going to change how the function is applied, so that you can have both full length and excerpt posts.

Before line 23 add a line:

Format::apply( 'autop', 'post_content_excerpt' );

Note that this line is important. Excerpts won't display properly unless the autop filter is first applied.

Then change line 23 to:

Format::apply_with_hook_params( 'more', 'post_content_excerpt', 'more', 100, 1 );

Note, you can use excerpt, summary, what ever you care to call it, you just need to be sure that you make the necessary changes in the following code

Now, if you notice in your home.php file (or entry.multiple.php), the content is being called using:

<?php echo $post->content_out; ?>

If you have made the previous change, your posts should now be full length. Now suppose you have somewhere you want to have excerpts. You can simply call:

<?php echo $post->content_excerpt; ?>

and your posts will be excerpts.

Personal tools