• Hello Everybody,
    Im trying to attach images with fixed url for the home page. It is 4 images for 4 posts, I’d like them to be different then the ones that are displayed in the post itself.

    Function that displays the attached image of post looks:

    // Post Attachment image function. Image URL for CSS Background.
    function the_post_image_url($size=large) {
    
    	global $post;
    	$linkedimgurl = get_post_meta ($post->ID, 'image_url', true);
    
    	if ( $images = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image',)))
    	{
    		foreach( $images as $image ) {
    			$attachmenturl=wp_get_attachment_image_src($image->ID, $size);
    			$attachmenturl=$attachmenturl[0];
    			$attachmentimage=wp_get_attachment_image( $image->ID, $size );
    
    			echo ''.$attachmenturl.'';
    		}
    
    	} elseif ( $linkedimgurl ) {
    
    		echo $linkedimgurl;
    
    	} elseif ( $linkedimgurl && $images = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image',)))
    	{
    		foreach( $images as $image ) {
    			$attachmenturl=wp_get_attachment_image_src($image->ID, $size);
    			$attachmenturl=$attachmenturl[0];
    			$attachmentimage=wp_get_attachment_image( $image->ID, $size );
    
    			echo ''.$attachmenturl.'';
    		}
    
    	} else {
    		echo '' . get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment.gif';
    	}
    }

    what I would like to do is add function “if post_id=? then img src=?” instead all that there is now for those 4 images, but since i’m not familiar with php, whatever I write returns blank pages. Please help:)

  • The topic ‘Attach home images to fixed URL.’ is closed to new replies.