Olivier Posted November 12, 2009 Share Posted November 12, 2009 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 Quote Link to comment Share on other sites More sharing options...
.josh Posted November 12, 2009 Share Posted November 12, 2009 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)); ?> Quote Link to comment Share on other sites More sharing options...
Olivier Posted November 12, 2009 Author Share Posted November 12, 2009 Wow! Perfect...! So simply yet it eluded me for so much time... Thanks! Cheers, Olivier Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.