How to place a 300x250 in the middle of text, without knowing length of the text?
Posted: 13 June 2008 08:49 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  80
Joined  02-05-2008

Hi all -

I am trying to figure out how to place a 300x250 image in the middle of a block of text that ranges in length from 750 to 1,000 words. The block of text is held in the {body} field of our weblog. The problem is, I can’t figure out how to place the image in the middle of the text, only at the top of the body of text, or at the bottom.

If I do this:

<img src="" />
{body}

the image displays at the top.

And if I do this:

{body}
<img src="" />

the image displays at the bottom.

I want the image displayed in the body—float: left—so that the text wraps around it. I tried using absolute positioning to force the image down into the page by 700 pixels, like this:

.300x250_ad {
    position
: absolute;
    
top: 700px;
    
left: 0;
}

but this plops the image right on top of the text, hiding it. The position was correct, though.

Does anyone have a suggestion?

Thanks!

Profile
 
 
Posted: 13 June 2008 09:22 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  411
Joined  02-28-2008

Image should really be in the body it self but to go along it should be nested layer with position of Relative using a box (padding, margin) concept of positioning.
eg.

<div id="body">
  
{body}
    
<div class="300x250_ad">
     <
img src="" />
    </
div>
</
div>


Even this will not guarantee that text will “wrap” around the image…so really why not inset an image as part of the body since it sounds like an image is part of the content/text.
All the best!

Profile
 
 
Posted: 13 June 2008 09:26 AM   [ Ignore ]   [ # 2 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6068
Joined  08-04-2002

You need to put it in right in the middle of the actual body text (where you want it to appear) in the entry and apply a css class (with appropriate margins/padding/etc) to it….
—————
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat < img src=”” class=“floatLeft” > lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat.
——-
< img src=”” class=“floatLeft” > Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat.
—————
Or you’d need to use javascript, php, etc. to do it programatically (automatically after so many words).

Profile
 
 
Posted: 13 June 2008 09:30 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  80
Joined  02-05-2008
lebisol - 13 June 2008 09:22 AM

why not inset an image as part of the body since it sounds like an image is part of the content/text.

I assume by this you mean insert the <img> tag within the body field on the Publish page? We don’t want to do this because we need the images to have their own custom fields.

Profile
 
 
Posted: 13 June 2008 10:05 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  411
Joined  02-28-2008
PXLated - 13 June 2008 09:26 AM

....Or you’d need to use javascript, php, etc. to do it programatically (automatically after so many words).

This was going to be my next suggestion…..you will have to dig for trim functions etc.
Quite nasty for ‘small’ visual effect…
All the best!

Profile
 
 
Posted: 13 June 2008 10:51 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1441
Joined  09-16-2004

It’s not a full blown solution but I had to do something similar for a site a while back: insert an image (actually a thumbnail link for a lightbox) after the second paragraph in a body of text.
See this thread for a rough start of a php solution.
Another way would be to use javascript (big fan of jQuery myself0 to remove the img from the dom and reinsert it (roughly) in the middle of the text.

How does your {body} look by the way, just 1 paragraph holding the entire block of text or several paragraphs?

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 16 June 2008 02:24 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  80
Joined  02-05-2008

e-man -

Thanks for that thread. It was helpful. I ended up doing something similar.

For the record, I don’t think this is possible without resorting to PHP.

Basically what I did was estimate roughly how far into the article I wanted the box ad to appear. I chose 1000 characters (somewhat arbitrary). Using PHP’s strpos function, I find the exact position of the first instance of “</p>” after this 1000th character starting point. This position represents where the paragraph that contains that 1000th character ends. I then stick all the text before that position into one string variable, and all text after it into another, and I “echo” my ad text between them. Like so:

<?php
    $text_full
= '{body}';
    
$offset = strpos($text_full, "</p>", 1000);
    
$text_1 = substr($text_full, 0, ($offset+4)); // the +4 is for the 4 characters "</p>"
    
$text_2 = substr($text_full, ($offset+4), strlen($text_full));
    echo
$text_1;
    echo
'<div class="big-box-ad ad-left">{embed="embeds/ad_300x250"}</div>';
    echo
$text_2;
?>

That’s it, roughly. Note that this solution assumes the body field is XHTML.

A few live examples:
http://www.urbanturf.com/articles/news_trends/dc_has_4th_highest_median_rents_in_country/
http://www.urbanturf.com/articles/news_trends/should_friends_buy_property_together/
http://www.urbanturf.com/articles/news_trends/credit_score_do_you_know_yours/

Thanks for everyone’s help!

Will

Profile
 
 
Posted: 16 June 2008 02:35 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1441
Joined  09-16-2004

Glad it helped! I actually had to check those pages in Safari as in FF the adblock plus extension blocked the ad completely smile
Nice-looking site BTW!

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 16 June 2008 03:41 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  80
Joined  02-05-2008

Thanks!

Profile
 
 
Posted: 16 June 2008 11:49 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

You could always use LG Replace (http://expressionengine.com/forums/viewthread/76788/) rather than php. Of course it would still involve some work from the editor which might not be what you want.

 Signature 

Nominate LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 17 June 2008 10:19 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1053
Joined  06-05-2007

Nice plug.  LOL  LOL

 Signature 

grantmx | designs - design | development | photography | consulting | ee pro profile

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64536 Total Logged-in Users: 15
Total Topics: 81116 Total Anonymous Users: 16
Total Replies: 436448 Total Guests: 181
Total Posts: 517564    
Members ( View Memberlist )
Newest Members:  Len HendricksmarlusbluespotmusicvolandspinhirnetheminiokostiamasterjeMBossbchaley