Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • that fixed it. not too intuitive that there is another duplicate place for options but you DID make a note in the general settings that I missed. Thanks for the free plugin.

    The admin option to turn off quotes doesn’t work.

    Thread Starter josephknight

    (@josephknight)

    Also, in the admin page for the plugin, in your example you tell the folks that to use groups enter a rel attribute with “lightbox” plus the groupname. However you proceed to show them an example of:

    <a href="images/image-1.jpg" rel="roadtrip[roadtrip]">image #1</a>
    <a href="images/image-2.jpg" rel="roadtrip[roadtrip]">image #2</a>
    <a href="images/image-3.jpg" rel="roadtrip[roadtrip]">image #3</a>

    These should be:

    ... rel="lightbox[roadtrip]" ...

    Hello, this is what’s working for me. May be some bugs I missed but so far so good. I’m using your above query and also sorting by menu_order so that if it’s pulling from a gallery it grabs the first image that YOU set as the first image (using the gallery’s menu order feature) regardless of what order it appears in the mysql db.

    Just use:
    <?php first_image(80, 80, 1)?> within the loop. Parameters are ($width, $height, $crop_when_zooming?).

    Also you can call any of the four functions directly. The get_* functions will return the just the image’s src element without echoing the surrounding <img> tag.

    first_image(*,*) conveniently makes the <img> tag for you.

    Here’s the working source:
    Make sure you have timthumb.php in your theme’s [theme_dir]/scripts folder.

    //return the first image, <img/> tag and all.
    function first_image($width=100,$height=100,$zoomcrop=1){
    	$timthumb_url = get_first_image($width, $height, $zoomcrop);
    	if(isset($timthumb_url)){
    		?>
    		<a href="<?php the_permalink()?>" class="thumbnail" title="Links to: <?php the_title()?>">
    			<img src="<?php echo $timthumb_url?>" alt="<?php the_title() ?>" class="thumbnail"/>
    		</a>
    		<?php
    	}
    }
    
    //return just the src for the first image whether that be in the content or an attachment
    function get_first_image($width=100,$height=100,$zoomcrop=1){
    	$tn_src = get_first_content_image();
    	if (!isset($tn_src)) //no image? try getting an attached image instead (native media galleries inserted into posts use attachments)
    		$tn_src = get_first_attachment();
    
    	if(isset($tn_src))
    		$timthumb_url = get_bloginfo('template_url').'/scripts/timthumb.php?src='.$tn_src.'&h='.$height.'&w='.$width.'&zc='.$zoomcrop;
    	else
    		unset($timthumb_url);
    
    	return $timthumb_url;
    }
    
    //return just the src for the first image buried in the post's textual content.
    function get_first_content_image() {
    	global $post, $posts;
    	$first_img = '';
    	$url = get_bloginfo('url');
    	ob_start();
    	ob_end_clean();
    	$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    	$first_img = $matches [1] [0];
    
    	$not_broken = @fopen("$first_img","r"); // checks if the image exists
    	if(empty($first_img) || !($not_broken)){ //Defines a default image
    		unset($first_img);
    	}else{
    		$first_img = str_replace($url, '', $first_img);
    	}
    	return $first_img;
    }
    
    //return just the src for the first image attachment
    function get_first_attachment(){
    	$querystr =
    	"
    		SELECT
    				wp_posts.post_excerpt AS 'imageTitle'
    			,	wp_posts.guid AS 'imageGuid'
    		FROM
    			wp_posts
    		WHERE
    				wp_posts.post_parent = ".get_the_ID()."
    			AND	wp_posts.post_type = \"attachment\"
    		ORDER BY \"menu_order\"
    		LIMIT 1
    	";
    	global $wpdb;
    	$url = get_bloginfo('url');
    
    	$post_item = $wpdb->get_row($querystr);
    	$first_attachment = $post_item->imageGuid;
    
    	$not_broken = @fopen("$first_attachment","r"); // checks if the image exists
    	if(empty($first_attachment) || !($not_broken)){ //Defines a default image
    		unset($first_attachment);
    	}else{
    		$first_attachment = str_replace($url, '', $first_attachment);
    	}
    
    	return $first_attachment;
    }
Viewing 4 replies - 1 through 4 (of 4 total)