简体   繁体   English

PHP和简码中的Wordpress PHP

[英]Wordpress PHP within PHP and shortcode

I am building a wordpress ecommerce template with Cart66 plugin. 我正在使用Cart66插件构建wordpress电子商务模板。 Using a Cart66 shortcode inside a php template page, I would like to generate the Post ID inside the shortcode. 在PHP模板页面内使用Cart66简码,我想在简码内生成Post ID。 Can someone please help and tell me if this is possible. 有人可以帮忙告诉我是否可行。 Here is the code that I am using. 这是我正在使用的代码。

<?php echo do_shortcode("[add_to_cart item=\\". the_ID() .\\" quantity=\\"user:1\\"]"); ?>

This code will lay inside loop-single.php and above 此代码将放置在loop-single.php及更高版本中

Thank you! 谢谢!

@silent几乎拥有它,但是应该是get_the_ID()而不是the_ID()因为后面的一个会回显它,因此请尝试:

<?php echo do_shortcode("[add_to_cart item=\"". get_the_ID() ."\" quantity=\"user:1\"]"); ?>

正确的行应该是:

<?php echo do_shortcode("[add_to_cart item=\"". the_ID() ."\" quantity=\"user:1\"]"); ?>

更简单的正确答案:

<?php echo do_shortcode('[add_to_cart item="'. get_the_ID() .'" quantity="user:1"]');?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM