PHP Syntax with variables
I am using the wordpress shopp plugin to sell products on my site. On my template file, I am using a shopp short code to display a particular category. It looks like this:
<?php shopp('catalog','category','load=true&id=16'); ?>
I would like the number 16 to be changeable, so I have stored the correct dynamic number in a variable as follows:
<?php $shopid = get_field('store_id'); ?>
The Variable $shopid
is the correct number that should replace the '16
' above. The question is, how do I place a vari开发者_运维百科able in the shopp shortcode? I tried as follows without luck:
<?php shopp('catalog','category','load=true&id=$shopid'); ?>
Any ideas how to pull this off?
Within single-quoted strings variables are not getting replaced by their values:
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
Use double quotes or string concatenation instead:
shopp('catalog','category',"load=true&id=$shopid")
shopp('catalog','category','load=true&id='.$shopid)
Either
<?php shopp('catalog','category',"load=true&id=$shopid"); ?>
Notice the double quotes. Or:
<?php shopp('catalog','category','load=true&id=' . $shopid); ?>
This is concatenation.
精彩评论