1 / 7
Nov 2009

Hi,



I am developing a site in WordPress based on the Mimbo theme, which uses software called TimThumb to automatically generate thumbnail images for posts for display on the home page etc. The problem is that when I add E-Junkie buttons to posts the thumbnail for any post containing E-Junkie buttons fail to display on the home page.



I have tried using the non-javascript buttons but it makes no difference. I have looked at the generated source code for the home page and it is clear that somehow when I add E-Junkie the button code screws up the paths to to the TimThumb images.



This is what a working image code looks like:



<img alt="" src="http://dramatisdei.com/wp-content/themes/dramatis/scripts/timthumb.php?zc=1&w=60&h=60&src=/wp-content/uploads/2009/07/MarmiteJesus2701.jpg" /></a>



and this is the broken image:



<img alt="" src="http://dramatisdei.com/wp-content/themes/dramatis/scripts/timthumb.php?zc=1&w=60&h=60&src=/ej/ejview_cart.gif" /></a>



The second src statement now has a path of "src=/ej/ej_view_cart.gif" substituted.



Anyone any Ideas how to get round this? Anyone experienced anything similar? I really really want to use E-Junkie!

  • created

    Nov '09
  • last reply

    Nov '09
  • 6

    replies

  • 1.2k

    views

  • 2

    users

  • 11

    links

Can you check the documentaion of TimThumb to see if they let you add a paramter to to the img tag which makes it "skip" that particular image?

Hmm, I'll look to see if there is relevant documentation but only thumbnails the first image in a post so I don't understand why it would be looking at the button images anyway.

I couldn't find why this was happening but on reflection decided to do this a whole different way. I thought I would share my solution here for anyone else using WordPress.



Basically, I put the script element of the View Cart code in my header template (header.php), the rest of the View Cart code and the Add To Cart code in the post template (single.php), and then added a custom field to the post to pass the E-Junkie Item No to the button code.



It works and was far easier than I had thought it might be! I'll give the details now.





First, take the script code from the View Cart code - that's everything between the first "<script" and the final "script>" - should be about six lines. Insert it into your header template (header.php) in the <head> section - I put it just before the "<link rel=" lines.





Second, look at your Add To Cart code and find the item number - it is the number that comes straight after the "i=", mine was a six digit number. Make a note of that number. Now, go to edit your post where you want the buttons. Towards the bottom of the page you have a big block headed "Custom Fields". Create a custom field by adding a meaningful field name (I used "ej_itemno"), and add the item number you just noted in the value box. Publish the post. That itemno is now linked to the post.





Third, edit your single post template (single.php). just before or after the main content (displayed using the line starting "<?php the_content") paste your Add To Cart and View Cart button code (minus the script bit you've already put in the header). Now, where the itemno appears ("i=xxxxxx") replace that with i=<?php echo(get_post_meta($post->ID, 'ej_itemno', true)); ?> (if your custom field wasn't called ej_itemno then change that bit). This will pump your itemno from the post into the code.



You want to only show the buttons where the post has an E-Junkie itemno so surround the code you've just pasted with these lines:



<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>

<p>

</p>

<?php } ?>



Your finished code will look something like this:



<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>

<p>

<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=<?php echo(getpost_meta($post->ID, 'ej_itemno', true)); ?>&cl=12345&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejadd_to_cart.gif" border="0" alt="Add to Cart"/></a>

<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&cl=12345&ejc=2" target="ejejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejview_cart.gif" border="0" alt="View Cart"/></a>

</p>

<?php } ?>



(remember not to just cut and paste the code above because your code will be different )



That's it! in any post, if you put an E-Junkie item no (from your item's button code) in your new custom field, the buttons will magically appear. And if you don't - they won't!







Hey, it works for me anyway!

I couldn't find why this was happening but on reflection decided to do this a whole different way. I thought I would share my solution here for anyone else using WordPress.



Basically, I put the script element of the View Cart code in my header template (header.php), the rest of the View Cart code and the Add To Cart code in the post template (single.php), and then added a custom field to the post to pass the E-Junkie Item No to the button code.



It works and was far easier than I had thought it might be! I'll give the details now.





First, take the script code from the View Cart code - that's everything between the first "<script" and the final "script>" - should be about six lines. Insert it into your header template (header.php) in the <head> section - I put it just before the "<link rel=" lines.





Second, look at your Add To Cart code and find the item number - it is the number that comes straight after the "i=", mine was a six digit number. Make a note of that number. Now, go to edit your post where you want the buttons. Towards the bottom of the page you have a big block headed "Custom Fields". Create a custom field by adding a meaningful field name (I used "ej_itemno"), and add the item number you just noted in the value box. Publish the post. That itemno is now linked to the post.





Third, edit your single post template (single.php). just before or after the main content (displayed using the line starting "<?php the_content") paste your Add To Cart and View Cart button code (minus the script bit you've already put in the header). Now, where the itemno appears ("i=xxxxxx") replace that with i=<?php echo(get_post_meta($post->ID, 'ej_itemno', true)); ?> (if your custom field wasn't called ej_itemno then change that bit). This will pump your itemno from the post into the code.



You want to only show the buttons where the post has an E-Junkie itemno so surround the code you've just pasted with these lines:



<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>

<p>

</p>

<?php } ?>



Your finished code will look something like this:



<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>

<p>

<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=<?php echo(getpost_meta($post->ID, 'ej_itemno', true)); ?>&cl=12345&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejadd_to_cart.gif" border="0" alt="Add to Cart"/></a>

<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&cl=12345&ejc=2" target="ejejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejview_cart.gif" border="0" alt="View Cart"/></a>

</p>

<?php } ?>



(remember not to just cut and paste the code above because your code will be different )



That's it! in any post, if you put an E-Junkie item no (from your item's button code) in your new custom field, the buttons will magically appear. And if you don't - they won't!







Hey, it works for me anyway!