shopp_add_image()

add an image by filename, and associate with a user defined context

shopp_add_image ( $id, $context, $file )

@param int $id Object id to attach the image asset to.
@param string $context the object type the image asset will be attached to.  This can be product or category
@param string $file Full or correct relative path to the image file.
@return mixed false on failure, int image asset id on success.

Description

Add an image by filename, and associate with a user defined context.

Requires full path to the file on your filesystem, or a correct relative path from the WP_CONTENT_DIR. The file will be stored in the currently active storage engine.

Example

associate image with a category

$file = '/path/to/file.jpg';

// add image to category 5
$id = shopp_add_image( 5, 'category', $file );

// load the category and display the image
ShoppCollection( shopp_product_category(5) );

// display new image using named image setting 'showcase'
shopp( 'collection', 'image', array( 'id' => $id, 'setting' => 'showcase') );

associate image with a product

$file = '/path/to/file.jpg';

// Lookup product named "My Product"
$Product = shopp_product( 'My Product', 'name');

// add image to product named "My Product"
$id = shopp_add_image( $Product->id, 'product', $file );

// set the product to the global product context
ShoppProduct( $Product );

// display new image using the named image setting 'showcase'
shopp( 'product', 'image', "id=$id&setting=showcase");

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar