Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hey there I have a stupid problem I'm having trying to integrate a button in wordpress. I have a plugin called wp azon builder which has an onsite cart button (add to cart stays on site) then I have the theme knightzon which has a cart button but the knightzon button links to amazon directly. I need to change this so it adds to onsitecart like the plugin.

I have it mostly figured out I just can't seem to reference the post id from outside the plugin framework. Sounds easy I'm just tired of it.

http://www.syracusefanpages.com
You can see what I'm trying to do in the slider I have it almost working LOL, and I included a working button example in the list view, but its pointing to a static product for demonstration purposes. I'd like to use the gray button image.

Update

I need to know how to call the page ID, I guess? This is what I was using:

<?php the_post(); ?>

Here is the plugin button code from the source, (what I want):

// on-site cart 
if (get_option('amzn-onsitecart') == "Yes") { 
    $addtocartcode = '<a [relnofollow] [targetblank] title="[Title]" href="#" onClick="amzn_onsitecartAdd('."'". $postid ."'".');" class="amzn_buynowimage amzn_addtocart_onsite_link"><img src="[PluginURL]/buttons/'.$addtocartimg.'"></a>'; 
}

Here is what I have currently (it doesn't see the button function I'm guessing from not properly calling the post id)

<a rel="nofollow" target="_blank" title="<?php the_title(); ?>" href= '#' onclick="amzn_onsitecartAdd('<?php the_post(); ?>');" class="amzn_buynowimage amzn_addtocart_onsite_link"><img(can't-post-image here so remove this)) src="http://www.syracusefanpages.com/wp-content/plugins/amzn/buttons/_addtocart-legacy.png"></a>;

The gray button from theme is what I'd like to use but that's not important, I just can't get the function to function, :-)

share|improve this question
3  
Please edit your question to include any and all relevant code. Otherwise, we have no possible way to try to answer the question. –  Chip Bennett Mar 23 '13 at 16:13
    
Your usage of the_post suggests that you are missing critically important knowledge of basic post loops. I STRONGLY suggest you read this: slideshare.net/andrewnacin/… else you may be incapable of using or understanding any answers given to you –  Tom J Nowell Mar 25 '13 at 15:19
add comment

1 Answer

I'm surprised, your site works as desired, if you really call the_post for the button. This function does not echo the post's ID, it simply fetches the next post of the current query.

If I understood you correctly (and I'm not so sure about that), you only want to get the current post's ID so you can work with it, right?

All you need to do is call the_ID(); wherever you want to output the ID. If you want to pass it to a function or in some way want to work with the data, use get_the_ID(); instead.

In your case, this would be:

<a href="#" onclick="amzn_onsitecartAdd('<?php the_ID(); ?>');" ...
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.