Jump to content

[SOLVED] Combining "print strip_tags" and "print string_limit_words"


Olivier

Recommended Posts

Hi everyone,

 

I am a Wordpress user (2.8.5) and I use FeedWordPress as a RSS feed aggregator to pull news from various sites. It does exactly what I need it to do, but admitedly by the RSS aggregator developer, it has some issues in handling 'get_the_excerpt' call.

 

So, I have been wrestling with trying to combine a "print strip_tags" and a "print string_limit_words" together into one workable "if" statement, which calls 'get_the_excerpt'.

 

Basically, on my home page, I would like to control the display of the incoming posts and achieve/apply 2 conditions on 'get_the_excerpt':

 

1 - strip all tags from each RSS post

2 - limit the number of words of 'get_the_except' to 35 instead of the Wordpress standard 55

 

Here's my current code:

<p style="font-size:0.9em;color:#666666;padding:5px 0px 0px 0px;">
     <?php if (is_syndicated()) : ?>
          <?php print strip_tags(get_the_excerpt()); ?>
          <?php print string_limit_words(get_the_excerpt(),35); ?> ... 
          <a style="font-size:0.8em;font-style:italic;color:#990000;" href="<?php the_permalink() ?>" rel="bookmark"><?php echo $newspaper["readMore"]; ?> »</a>
     <?php endif; ?>
</p>

 

where <?php if (is_syndicated()) : ?> is the conditional call for the RSS posts.

 

The current code does not work as it returns 'get_the_excerpt' twice in their respective formats.

 

If I use <?php print strip_tags(get_the_excerpt()); ?> alone (removing <?php print string_limit_words(get_the_excerpt(),35); ?>), it does strips out all tags (which is one of the things I want to do) BUT somehow the standard 55 words limit from 'get_the_excerpt' is ignored, and the full post is displayed instead (which I do not want).

 

If I use <?php print string_limit_words(get_the_excerpt(),35); ?> alone (removing <?php print strip_tags(get_the_excerpt()); ?>), 'get_the_excerpt' behaves properly (returns the 1st 35 words), but none of the tags have been stripped.

 

I tried combining both such as below:

 

<?php print strip_tags(get_the_excerpt(print string_limit_words(get_the_excerpt(),35))); ?>

 

but to no avail... I have tried many different ways but with no success, and now I am confused... and running out of ideas... :)

 

So, here it is... what would be the code to apply both filters (strip tags and limit words) to 'get_the_excerpt', when the posts is from the syndicated source?

 

Many thanks for your help and feedback,

 

Cheers,

 

Olivier

 

assuming get_the_excerpt() returns a string containing whatever, and assuming string_limit_words() returns that string truncated to 35 chars...

 

<?php print strip_tags(string_limit_words(get_the_excerpt(),35)); ?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.