Zen Cart Logo
Forums / General Questions / PHP Question: Adding href to Manufacturer image

PHP Question: Adding href to Manufacturer image

Views: 436

Results 1 to 10 of 10
27 Jan 2016, 4:34 PM
#1
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

PHP Question: Adding href to Manufacturer image

Hello,

A while back I added my manufacturers' logos to product pages by inserting this code:

<!--bof: Mfg logo image --> <?php if ($check_image = zen_get_products_manufacturers_image((int)$_GET['products_id'])) { echo '<a class="manufacturer">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ; } else { echo ' '; } ?> <!--eof: Mfg logo image -->

You can see it in action here:
http://2staging.apswittcosalesDOTcom/Fine-L-Kotetrade_SR_Silicon_Conformal_Coating_2102-12S_12_oz._Aerosol

Now I would now like to make that Techspray logo clickable, redirecting here:
http://2staging.apswittcosalesDOTcom/index.php?main_page=index&manufacturers_id=31

Here is an example of code that generates the href I want:

<a href="' . DIR_WS_CATALOG . 'index.php?main_page=index&manufacturers_id=' . $manufacturers->fields['manufacturers_id'] . '">';

I just can't figure out how to wrap my image.

Can someone help me, pretty please! :D

27 Jan 2016, 5:04 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP Question: Adding href to Manufacturer image

You could try this:

echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ;
27 Jan 2016, 5:21 PM
#3
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: PHP Question: Adding href to Manufacturer image

Thanks, Ajeh!

When I tried replacing the echo statement with yours, it breaks site: :(

<?php if ($check_image = zen_get_products_manufacturers_image((int)$_GET['products_id'])) { echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ; } else { echo ' '; } ?>

When I tried replacing the entire statement just to see if it would work like this:

<?php echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ; ?>

...the logo gets replaced by my standard No_Image.jpg... but the link works!!!

Getting close!

27 Jan 2016, 5:26 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP Question: Adding href to Manufacturer image

That IF makes the variable $check_image and if you remove the IF, then $check_image does not exist and it is part of what displays the image as that is the image ...

27 Jan 2016, 5:34 PM
#5
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: PHP Question: Adding href to Manufacturer image

So, this should have worked, right?

<?php if ($check_image = zen_get_products_manufacturers_image((int)$_GET['products_id'])) { echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ; } else { echo ' '; } ?>

But it breaks the page :(

What am I doing wrong? Is it that second $check_image?

27 Jan 2016, 5:44 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP Question: Adding href to Manufacturer image

This is what I have based on what you you originally posted but I just added another echo for giggles and grins:

<!--bof: Mfg logo image -->
<?php
echo '<br>Does this work below?' . '<br>';
if ($check_image = zen_get_products_manufacturers_image((int)$_GET['products_id'])) {
//echo '<a class="manufacturer">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ;
echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ;
} else {
echo ' ';
}
?>
<!--eof: Mfg logo image -->
27 Jan 2016, 5:49 PM
#7
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: PHP Question: Adding href to Manufacturer image

It works!!!! Yaaaaaay! Thank you, thank you, thank you!

This is what is up now:

<!--bof: Mfg logo image --> <?php if ($check_image = zen_get_products_manufacturers_image((int)$_GET['products_id'])) { echo '<a class="manufacturer" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $product_info->fields['manufacturers_id']) . '">' . zen_image(DIR_WS_IMAGES . $check_image) . '</a>' . "\n" ; } else { echo ' '; } ?> <!--eof: Mfg logo image -->

You rock!

27 Jan 2016, 5:54 PM
#8
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: PHP Question: Adding href to Manufacturer image

Quick follow on... :D

Is there a way I can limit the width of my image to, say, no wider than 200px?

I don't want to stretch an image that is smaller, just prevent it from being too wide.

And...
Can I auto tag the image with a description, say MFG_NAME + " catalog"?

Thank you again for your awesome help!

27 Jan 2016, 5:55 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: PHP Question: Adding href to Manufacturer image

Coolness ... had me wondering for a bit there as I tested it originally in Zen Cart v1.5.4 and thought maybe there was something different in v1.5.1 and it wsa not picking up the manufacturers_id ... then I stuck it in v1.5.1 and it still worked ... :lookaroun

Glad to hear that this was you and not me ... :smile:

27 Jan 2016, 5:58 PM
#10
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: PHP Question: Adding href to Manufacturer image

Yeah, I have no idea what I did wrong. I followed your first instructions correctly, but it wonky for some reason. Second time I tried, worked like a charm!