Feed owners on my site complain that their entire feed item gets placed on their site - so the viewers of their feed on my site have no reason to go to their site. That's a legit concern.

Is there anyway to reduce the length of what is shown on my site so there is just the first few lines and then the viewer is urged to visit the source to read the rest?

That way both sites get the traffic.

I know it's usually a setting on the blog itself where the owner can stipulate how long their feed is that goes OUT but not many bloggers are savvy enough to change their settings themselves. ;)

Comments

vannen’s picture

As far as I can see, a user scanning a site for the headlines would find the task much easier if the items were all of uniform length, so having an option to regulate the text length appears to be a good idea.

Perhaps the "cleanest" way of doing this is in the node template for feed items. That way, you keep the entire node text in the database, don't modify the module, but still trim down the feed item text.

however, this option requires inserting extra code into the node template, meaning that overhead could be an issue for a busy site with many feed items. Truncating the text before it's inserted into the database saves space and would make rendering the feed items quicker.

I've coded the beginning of a solution to this problem that lets an administrator set the length in characters of the displayed text be set, in the Simplefeed settings. The code below could be inserted into simplefeed.module:

At line 426:

    $form['simplefeed_max_body_text_chars'] = array(
    '#type' => 'textfield', '#title' => t('Maximum characters in feed item body text. Set as zero for unlimited'), '#size' => 4, '#maxlength' => 4,
    '#default_value' => variable_get('simplefeed_max_body_text_chars', 0),
    '#description' => t('The maximum length of item text in characters displayed. Does not truncate the saved description in database.')
  ); 

At line 451 (note the replaced closing bracket at the top)

  }
  // Maximum number of characters in the text must be a number
  if (!is_finite($form_values['simplefeed_max_body_text_chars'])) {
    form_set_error('simplefeed_max_body_text_chars', t('Maximum number of characters in feed item text must be a number.'));
  }

This creates the variable simplefeed_max_body_text_chars, which could be accessed from either the node template of a theme or in the simplefeed_item module.

In order to truncate the text in a node template (this works for a Zen sub-theme, it'll need to be tested for other themes) add the following code in the content div of node.tpl.php, then save it as node-feed_item.tpl.php in your theme/sub-theme directory:

   // used ereg_replace because other functions such as strip_tags don't replace tags with anything.
   $content = ereg_replace('<[^>]+>', ' ', $content);
   // If maximum characters is set, truncate. Otherwise, don't.
   if(($simplefeed_max_chars = variable_get("simplefeed_max_body_text_chars", 0))!=0) {
      $content = substr($content, 0, $simplefeed_max_chars);
      // If the truncation chops a word, truncate at last space between words. This is not foolproff but works for the majority of items.
      if(substr($content, -1) != " ") {
        $content = substr($content, 0, ($simplefeed_max_chars -(strlen(strrchr($content, " "))))); 
      }
   // Add an elipsis.
   $content.="..."; 
   }

In order to truncate the text before it gets inserted into the database, you would need to insert similar (not the same!) code at line 357 of simplefeed_item.module. The problem with the above code is that it strips tags out of the content in order to uniformly truncate the text so any truncated text will loose tagged content such as links and pictures.

I haven't taken ownership of this issue as the code needs testing on different systems and some improvement. I hope this gives people a start.

vannen’s picture

Just to add that with the above code you would go to admin/settings/simplefeed and set the maximum characters there. The default is zero, which does not truncate the text. Anything above zero will set the maximum.

vannen’s picture

Status: Active » Needs work

Setting to "needs work".

Scott Reynolds’s picture

Status: Needs work » Closed (works as designed)

Feed owners on my site complain that their entire feed item gets placed on their site - so the viewers of their feed on my site have no reason to go to their site. That's a legit concern.

why then did they put the whole post in their feed.

This seems like a non-issue to me.

As mentioned, you can theme up the feed_item so that its smaller if needed.