[thelist] CF: CMS Tips and Tricks?

Jay Blanchard jay.blanchard at niicommunications.com
Tue Aug 13 06:30:01 CDT 2002


[snip]
1) Images in the body of an article.
Up to this date, my system permitted one image per article, as defined by a
template. I would like to allow the non-technical user to simply choose to
upload an image and have it inserted in the middle of an article. (The
article is typed or pasted into a large text-area, right now.) How can I
have multiple images intermingled with copy, that is not based on a hard
coded template?

One solution I thought of, but seems a too clumsy to me is to return a
'code' (eg:   [[261-2.jpg]]  ) and have the user paste it in, but that
seems a little complex for some of my users (trust me, they would muck it
up).
[/snip]

If you are maintaining the images (image URL's actually) and the article in
a database you could do something such as this; (template pseudo-code, using
PHP)

<?php
print($ArticleTitle . "<br>\n");
print($Author . "<br>\n");

print($Image1URL . "<br>"\n); // first image at top of article

$paragraph_break = 1;

while(print($ArticleBody)){
   if($thisline == double_line_break){
      $paragraph_break++;
      if($paragraph_break == 3){
         print($Image2URL . "<br>\n"); // second image before paragraph 3
      }
   }
}
?>

I hope this gives you some ideas. Count the paragraph breaks and insert
images where you want them between paragraphs. You could also do the sam
thing for small images that are "within" paragraphs by counting lines in the
body.

HTH!

Jay





More information about the thelist mailing list