Is there a way to limit the word count in the teaser to something like 100 words exactly... no matter if it breaks a sentence up?

Comments

vm’s picture

administer -> post settings

stephtek’s picture

ya there is 200 or 400 or unlimited. I am wondering if it is possible to make it more exact? Exactly 100 words.

Jeff Burnz’s picture

take a gander at this thread, theres 2 functions you could use that I posted, one trims to a character count, the other to a word count.

http://drupal.org/node/343014

its a long thread I know...

stephtek’s picture

dang.. didnt work for me. I am using CCK and contemplate. Here is my template code:

<div class="box">
	<div class="right-box-third-top">&nbsp;</div>
    <div class="right-box-third-middle">
<div class="featured-img"><?php print $node->field_featured_img[0]['view'] ?></div>

<div class="more-info"><a href="<?php print $node->path ?>" title="<?php print $title ?>">More Info <img src="http://tofinobeach.com.wedodns.com/sites/all/themes/tofinobeach/images/arrow-sm.gif" alt="Arrow" width="12" height="15" border="0"/></a></div><h1><a href="<?php print $node->path ?>" title="<?php print $title ?>"><?php print $title ?></a></h1>

<?php $string = word_trim($body, 100, TRUE); print $string; ?></div>
    <div class="right-box-third-bottom">&nbsp;</div>
</div>

and this is in my template.php

<?php
/**
* Trim a string to a given number of words
*
* @param $string
*   the original string
* @param $count
*   the word count
* @param $ellipsis
*   TRUE to add "..."
*   or use a string to define other character
* @param $node
*   provide the node and we'll set the $node->
* 
* @return
*   trimmed string with ellipsis added if it was truncated
*/
function word_trim($string, $count, $ellipsis = FALSE){
  $words = explode(' ', $string);
  if (count($words) > $count){
    array_splice($words, $count);
    $string = implode(' ', $words);
    if (is_string($ellipsis)){
      $string .= $ellipsis;
    }
    elseif ($ellipsis){
      $string .= '&hellip;';
    }
  }
  return $string;
}
?>
Jeff Burnz’s picture

Never used contemplate, but is $body the correct variable that contemplate tells you to use?

WorldFallz’s picture

$body should be $node->body.

peterx’s picture

An alternative for your consideration: http://drupal.org/project/excerpt

There are times when you want the teaser to be a summary in a specific format. Excerpt gives you that option by creating the teaser separate to the body. When you have to modify code to do something special to the teaser, you might find Excerpt a better starting point.

petermoulding.com/web_architect

grendzy’s picture

http://www.lullabot.com/articles/trim_a_string_to_a_given_word_count

Then I display the teaser using fields in views, and put the code in a template file (like views-view-field--comments-recent--comment.tpl.php).

toitimhcm’s picture

best way to do is that:
search table name variables

SELECT *
FROM `variable`
WHERE `name` LIKE '%teaser%'

edit

teaser_length s:3:"200";

to what ever you want
-------------------

smzur22’s picture

Is there no easy way to change post settings to give me the option "100" instead of 200?

grendzy’s picture

Try adding

$conf['teaser_length'] = 100;

To your settings.php

smzur22’s picture

Thanks mate! Worked great =)

bdsl’s picture

Isn't the setting for number of characters in the teaser, not number of words?

Also, note that this only affects teasers being generated as pages are saved. They are not generated on the flyer for viewing, so existing teasers will stay the same after this is altered.

vm’s picture

yes it is characters.

correct the setting is not retroactive but one can do a bulk operation on the previously saved node which would alter the previously saved node and force them to take on the new setting. One could also investigate the retease.module which aids in this type of thing.

markpetherbridge’s picture

Are you using a view block?

If so, in the views section, click edit on the block you want. Click 'Node: Teaser' in the filters section and then scroll down.
You will see a check box titled 'Trim this field to a maximum length' When that is clicked, you will have the option to type any value in.

Remember to save

vm’s picture

IIRC that field setting in views is still character length and not word length.

markpetherbridge’s picture

Didn't read it through correctly.

Have you tried: http://drupal.org/node/46391