Post-Thumb Forum » How-to's

Float text around thumb?

(9 posts)
  • Started 2 years ago by Kjetil
  • Latest reply from security_man

  1. Hi
    Is it somehow possible to make the text of a post float down around one side of the thumb image?
    I'm using PT to make a thumbnail at the top of every post - generated from the inital image in the post (just below the more tag.
    As it is, the thumbs show up (vertically) between the post title and the text. I would very much like it to appear to the left of this initial text instead. Possible?
    I use this code to get that thumb:
    '<?php the_thumb("link=p"); ?>'
    (It also links to the post.)
    Have a look at Dolcevita.no to see it works. (You might have to skip the wp in the url since I'm just moving the site.)
    Thanks,
    Kjetil

    Posted 2 years ago #
  2. I guess that means its not possible?
    Let me put it on the wish-list, then
    Kj

    Posted 2 years ago #
  3. The answer is not inside post-thumb but has to be in each style.css file. What you want to do is purely related to css styling.

    Posted 2 years ago #
  4. I understand that the layout is controlled in the css but when I add a margin of 5 px to the right of the thumbs in css.. nothing happens..

    Should i work with MYCLASSIMG ? If so, could you please give a hint as to how to?

    By the way.. I LOVE this plugin.. if you ask me it should be in WordPress by default!

    Posted 1 year ago #
  5. I have figured out how to by doing this:

    <div style="float:left; margin:0px 10px 5px 0px;">
    <?php the_thumb('link=p'); ?>
    </div>

    Hope that helps for anyone else having the same issue. Anyone interested to see what that looks like head on over to http://www.idimensie.nl

    Posted 1 year ago #
  6. the problem is that when the thumb is being rewritten it searches for an align= call. The new versions of wordpress dont use that any more and use a class of alignleft or alignright instead which makes post thumb output align="ft" or align="ght" because it is replacing the first two letters assuming it is an =". The solution is to open lib/post-thumb-library.php and around line #145 you will find the replaceimage function. replace it with the following:

    // begin fix float replace
    function ReplaceImage($content) {
    $attrList=array ("src", "alt", "title", "rel", "class");

    if (!$this->p_rel &&
    stripos($content, 'rel="thumb"') === false && stripos($content, "rel='thumb'") === false)
    return $content;

    // Thumbnails image and replace
    $pattern = '/<img([^>]*)\/>/si';
    if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {

    foreach ($matches as $match) :

    if (stripos($match[0], 'class="wp-smiley"')) continue;
    if (stripos($match[0], "class='wp-smiley'")) continue;

    if (!$this->p_rel){
    if (stripos($match[0], 'rel="thumb"') === false
    && stripos($match[0], "rel='thumb'") === false)
    continue;
    } else {
    if (stripos($match[0], 'rel="nothumb"') !== false || stripos($match[0], "rel='nothumb'") !== false)
    continue;
    }
    $match[1] = str_replace("rel='thumb'", '', $match[1]);
    $match[1] = str_replace('rel="thumb"', '', $match[1]);
    $match[1] = str_replace("rel='nothumb'", '', $match[1]);
    $match[1] = str_replace('rel="nothumb"', '', $match[1]);

    $m = str_replace('@', '\@', $match[0]);
    $m = str_replace(')', '\)', $m);
    $m = str_replace('(', '\(', $m);
    $pat = '@<a([^>]*)\>([^>]*)'.$m.'([^>]*)\<\/a>@si';

    if (preg_match($pat, $content, $foo)) {
    continue;
    }

    $ListAttr = pt_parseAtributes($match[1], $attrList);
    $ListAttr['ext'] = substr(strrchr($ListAttr['src'], "."), 1);
    $ListAttr['img'] = substr($ListAttr['src'],0,strlen($ListAttr['src']) - (strlen($ListAttr['ext']) + 1) );
    if ($ListAttr['title']=='' || !isset($ListAttr['title'])) $ListAttr['title'] = $ListAttr['alt'];
    $replacement = $this->MakeThumb($ListAttr);
    $content = str_replace($match[0], $replacement, $content);

    endforeach;
    }

    return $content;
    }
    // end fix float replace

    then under that function you will find the makethumb function. Replace it with the following:

    // begin fix float replace
    function MakeThumb($ListAttr) {

    // Initialize parameters
    $the_image = $ListAttr['img'].'.'.$ListAttr['ext'];
    $ListAttr['alt'] = htmlspecialchars($ListAttr['alt']);
    $ListAttr['title'] = htmlspecialchars($ListAttr['title']);

    if ($ListAttr['align'])
    $align = ' align="'.$ListAttr['align'].'"';
    else
    $align="";

    if ($ListAttr['rel']) {
    $rel = ' rel="'.$ListAttr['rel'].'"';
    } else {
    $rel = $this->lightbox;
    }

    // Prepare parameter for thumbnail
    $arg = 'ALTAPPEND='.get_pt_options('p_append_text').
    '&WIDTH='.get_pt_options('p_resize_width').
    '&HEIGHT='.get_pt_options('p_resize_height').
    $this->addArg;

    // Retrieve thumbnail
    $t = new pt_thumbnail ($the_image, $arg);
    $add_tag = $align;

    // Add thumbnail & highslide expand to image
    if (POSTTHUMB_USE_HS) {
    $h = new pt_highslide ($the_image, $t->thumb_url, $ListAttr['alt']);
    $h->set_borders (get_pt_options('ovframe'));
    $h->set_title ($ListAttr['title']);
    if ($this->p_has_caption)
    $h->set_caption (addslashes($ListAttr['alt']));
    $h->set_html_size();
    $h->set_href_text('', $add_tag);
    $h_str = $h->highslide_link ();
    unset ($h);
    }
    // Add thumbnail & thickbox/smoothbox class to image
    elseif (class_exists('pt_thickbox')) {
    $h = new pt_thickbox ($the_image, $t->thumb_url, $ListAttr['alt']);
    $h->set_href_text('', $add_tag);
    $h_str = $h->thickbox_link ();
    unset ($h);
    }
    // Simple replacement by thumbnail linked to image
    else $h_str = '<img src="'.$t->thumb_url.'" alt="'.$ListAttr['alt'].'" class="'.$ListAttr['class'].'" />';

    unset ($t);

    return $h_str;
    }
    // end fix float replace

    then open lib/post-thumb-functions.php and around line 154 find the pt_parseatributes function. replace the first line

    function pt_parseAtributes($html, $attrList=array ("src", "alt", "title", "align")) {

    with the following:

    function pt_parseAtributes($html, $attrList=array ("src", "alt", "title", "class")) {

    That is how i got it to work... i dont completely understand how those functions work together, but i think my work around will do the trick.

    the only problem i see now is that if you dont want the thumbnail linked in a post there is no way to do that.

    Posted 1 year ago #
  7. This will make things work in WP 2.6 - and also in 2.7?
    If so - brilliant!!!
    I've searched around a lot but still not found a good replacement for this plugin.
    Kjetil

    Posted 1 year ago #
  8. not sure about 2.7, but i do know it works in 2.6.5 cuz thats where i made those mods and it works great. Remember - you cannot link the thumbnail when you put it in a post or everything goes to hell, but if you are just adding images for design then its good.

    if you do need links on the thumbs, maybe someone more skilled than i can find the work around on that.

    Posted 1 year ago #
  9. oh crap... just double checked the code from this page and it looks like something has gone wonky when posted... lemme try again:

    function ReplaceImage($content) {
    		$attrList=array ("src", "alt", "title", "rel", "class");
    
    		if (!$this->p_rel &&
    			stripos($content, 'rel="thumb"') === false && stripos($content, "rel='thumb'") === false)
    		return $content;
    
    		// Thumbnails image and replace
    		$pattern = '/<img([^>]*)\/>/si';
    		if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
    
    			foreach ($matches as $match) :
    
    				if (stripos($match[0], 'class="wp-smiley"')) continue;
    				if (stripos($match[0], "class='wp-smiley'")) continue;
    
    				if (!$this->p_rel){
    					if (stripos($match[0], 'rel="thumb"') === false
    					&& stripos($match[0], "rel='thumb'") === false)
    						continue;
    				} else {
    					if (stripos($match[0], 'rel="nothumb"') !== false || stripos($match[0], "rel='nothumb'") !== false)
    						continue;
    				}
    				$match[1] = str_replace("rel='thumb'", '', $match[1]);
    				$match[1] = str_replace('rel="thumb"', '', $match[1]);
    				$match[1] = str_replace("rel='nothumb'", '', $match[1]);
    				$match[1] = str_replace('rel="nothumb"', '', $match[1]);
    
    				$m = str_replace('@', '\@', $match[0]);
    				$m = str_replace(')', '\)', $m);
    				$m = str_replace('(', '\(', $m);
    				$pat = '@<a([^>]*)\>([^>]*)'.$m.'([^>]*)\<\/a>@si';
    
    				if (preg_match($pat, $content, $foo)) {
    					continue;
    				}
    
    				$ListAttr = pt_parseAtributes($match[1], $attrList);
    				$ListAttr['ext'] = substr(strrchr($ListAttr['src'], "."), 1);
    				$ListAttr['img'] = substr($ListAttr['src'],0,strlen($ListAttr['src']) - (strlen($ListAttr['ext']) + 1) );
    				if ($ListAttr['title']=='' || !isset($ListAttr['title'])) $ListAttr['title'] = $ListAttr['alt'];
    				$replacement = $this->MakeThumb($ListAttr);
          				$content = str_replace($match[0], $replacement, $content);
    
    			endforeach;
    		}
    
    		return $content;
    	}

    yes that looks much better... sorry bout that :D

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.