You are here:  » Multiple images in wordpress

Support Forum



Multiple images in wordpress

Submitted by michael on Mon, 2012-07-16 20:54 in

hi david,
i have been working on my site for a week now and am really liking price tapestry. i have done some modifications to PT i have done multiple images in xml forgot what node also i have done node 822 for logging querys and the follow on node for most popular search. i have also set up 2 extra fields in the product database table one for currency and one for keywords.

basically what i would like to know is if there is a way to output these fields in wordpress and also as for one feed there is multiple images for each product i have managed to get the images into the database and display them in price tapestry but im not sure how to integrate multiple images into the wordpress plugin.

i tried to output some extra fields like currency with %CURRENCY% but to no avail. also tried some script for the logging on wordpress and couldn't get it to log the querys from wordpress.

Submitted by support on Tue, 2012-07-17 05:00

Hi Michael,

Thank you for your comments!

Custom fields can be output within the plugin using %DB_fieldname% - check out this page on PriceTapestry.org for more information. It is case sensitive, so if the custom field in your database is "currency" then the placeholder, which can be used anywhere within the Product / Main and Price / Each templates would be %DB_currency%

Cheers,
David.
--
PriceTapestry.com

Submitted by michael on Tue, 2012-07-17 19:48

Hi David

Thank you for the support.

Cheers
Michael

Submitted by michael on Wed, 2012-07-18 11:52

hi again David i managed to get the custom fields sorted thanks for the link, but im still having dificulty setting up wordpress to deal with multiple images, after a bit of searching i found the origial node i followed 4610. i need a way to set up the php in wordpress so its got the correct delimiter and foreach but i cant figure it out i tried vaious %IF_EVERY% combinations but nothing seemed to work for the images. it would be ideal if there is a way to include the php in the backend gui so i could set up the single image for the search results and featured products and multiple images on the product page. is this possible?

Submitted by support on Wed, 2012-07-18 12:10

Hello Michael,

I'll investigate the use of PHP code within templates (should be possible using 'eval') but in the mean time; a similar multiple images mod within the plugin would be as follows. First look for the following code at line 303 in pto_product.php:

$html_product = str_replace("%IMAGE_URL%",$product->image_url,$html_product);

...and REPLACE with:

$images_html = "";
$images = explode(",",$product->image_url);
foreach($images as $image_url)
{
  $images_html .= "<img width='180' src='".$image_url."' />";
}
$html_product = str_replace("%IMAGES%",$images_html,$html_product);

Finally, in your Product / Main template (wp-admin > Settings > PriceTapestry.org), in place of the default line:

<img class='pto_product_image' src='%IMAGE_URL%' />

...use just:

%IMAGES%

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by michael on Wed, 2012-07-18 21:47

hi david thanks for the help i managed to get the images to display with that, i just had to make one correction. i had to change:

$html_product = str_replace("%IMAGES%",$image_html,$html_product);

to:
$html_product = str_replace("%IMAGES%",$images_html,$html_product);

then it worked ive still got a problem with trying to output a single one on the search listings. i tried to create another link like this just below the end of that line?:
$image_single = $imagess;
$imagess = explode(",",$product->image_url);
$product->image_url = $images[0];
$html_product = str_replace("%IMAGE_S%",$image_single,$html_product);

and then tried to call it with:
%IF_IMAGE%
<img class='pto_product_image' src='%IMAGE_S%' />
%ENDIF_IMAGE%

but it didn't work, what am i doing wrong?

Submitted by michael on Wed, 2012-07-18 22:30

Ok so i managed to get it working so the whole thing is as follows:

    if ($product->image_url)
    {
      $images_html = "";
      $images = explode(",",$product->image_url);
      foreach($images as $image_url)
      {
        $images_html .= "<img width='180' src='".$image_url."' />";
      }
      $html_product = str_replace("%IMAGES%",$images_html,$html_product);
      $image_single = "";
      $images = explode(" ,",$product->image_url);
      $image_single = $images[0];
      $html_product = str_replace("%IMAGE_S%",$image_single,$html_product);
      $html_product = str_replace("%IF_IMAGE%","",$html_product);
      $html_product = str_replace("%ENDIF_IMAGE%","",$html_product);
    }
    else
    {
      $html_produc = preg_replace('/%IF_IMAGE%(.*)%ENDIF_IMAGE%/','',$html_product);
    }

and then call either %IMAGES% to output all images or %IMAGE_S% for a single image.
thanks for your help with this david!

Submitted by support on Thu, 2012-07-19 11:51

Thanks for the update, Michael, and I've corrected the inital typo above...

Cheers,
David.
--
PriceTapestry.com