Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Stripping images from article preview  (Read 2783 times)

sagaris

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Stripping images from article preview
« on: June 30, 2008, 06:29:31 PM »

Hi,

I was wondering if anybody can give me any pointers on how I would go about stripping certain tags from the short description (on category pages or home page), whilst leaving them in place in the full article? I have an article with a large image right at the top of the article which I want to exclude from the short intro whilst leaving it in place on the complete article.

I think the answer will lie in the file_include function although I am a little unsure how this function exactly works, and everything I have tried so far has changed the article itself as well as the short text.   ???

I am using 1.5.3.1, so I am posting this in the correct topic mods  :)

Thanks in advance for any help!

Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Stripping images from article preview
« Reply #1 on: June 30, 2008, 09:16:56 PM »

This is something that none of the Dudes have had time to explore further. Whatever eventually works will, most likely, work equally well for both 1.5.31 and 1.6... since both versions are... functionally-speaking... pretty much the same. My approach has been to re-locate the image links further down in the article, between paragraphs, to keep them "out of range" of the short-version cut-off point (character limit). Pretty well all of the sNews sites I've done as actual client projects never use the short intro functions... so I've not needed to find a better solution for my purposes.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: Stripping images from article preview
« Reply #2 on: July 01, 2008, 08:09:19 AM »

@sagaris : Replace in file_include() this:
Code: [Select]
$fulltext = substr($text, 0, $shorten);

with something like this:
Code: [Select]
if ( $shorten < 9999000 )
{
$fulltext = substr(strip_tags($text, 'div,p,a,br'), 0, $shorten);
}
else
{
$fulltext = substr($text, 0, $shorten);
}
Logged

sagaris

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Re: Stripping images from article preview
« Reply #3 on: July 01, 2008, 01:26:09 PM »

Thanks for the suggestions guys - the code suggested by codetwist acheived the desired effect, apart from a slight bug of stopping the [break] functionallity working properly, I therefore modified the code to use a regular expression to remove the images as a quick fix

Code: [Select]
if ( $shorten < 9999000 )
{
$fulltext = substr(preg_replace('/<img.*src="".*\/>/', '', $text), 0, $shorten);
}
else
{
$fulltext = substr($text, 0, $shorten);
}


but the strip tags option is a much more flexible long term solution which I will look at getting to work with the [break] functionality when I get a moment.

Thanks again for the help guys

Logged