Php 将变量显示为链接
我正在使用Wordpress,我在woocommerce开了一家商店。我试图在产品页面上显示品牌名称作为链接,但我对代码有困难。到目前为止,我已经:Php 将变量显示为链接,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用Wordpress,我在woocommerce开了一家商店。我试图在产品页面上显示品牌名称作为链接,但我对代码有困难。到目前为止,我已经: <?php $brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") ); echo "Brend: "; foreach( $brands as $brand ) { $url = get_term_l
<?php $brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") );
echo "Brend: ";
foreach( $brands as $brand ) {
$url = get_term_link( $brand->slug, 'product_brand' );
echo '<a href="' . $url . $brand->name '"></a>';
}?>
我得到以下错误:
分析错误:语法错误,意外的“”“>”(T_常量_封装的_字符串),第6行的代码中应为“,”或“;”
我看不出我做错了什么。任何帮助都将不胜感激。您缺少此处的连接
$brand->name
:
echo '<a href="' . $url . $brand->name '"></a>';
您缺少此处的连接
$brand->name
:
echo '<a href="' . $url . $brand->name '"></a>';
检查:
<?php $brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") );
echo "Brend: ";
foreach( $brands as $brand ) {
$url = get_term_link( $brand->slug, 'product_brand' );
echo '<a href="' . $url . $brand->name .'">'.$brand->name.'</a>';
}?>
检查:
<?php $brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") );
echo "Brend: ";
foreach( $brands as $brand ) {
$url = get_term_link( $brand->slug, 'product_brand' );
echo '<a href="' . $url . $brand->name .'">'.$brand->name.'</a>';
}?>
echo“”;echo“”;
使用thisecho“”;echo“”;
使用thisThanx作为回复,我尝试了这个,错误消失了。但是我现在看不到任何品牌名称。有什么建议吗?Thanx。@Nancy:print\r($brands)
在循环之前使用它并共享结果,这样做了,结果是Brend:Array([0]=>WP\U术语对象([Term\U id]=>65[name]=>Nokia[slug]=>Nokia[Term\U group]=>0[Term\U分类id]=>65[taxonomy]=>product\U brand[description]=>0[count]=>1[filter]=>raw][1]=>WP\U术语对象([Term\U id]=>66[name]=>Samsung[slug]=>Samsung[Term\U group]=>0[Term\U分类id]=>[description]=>[parent]=>0[count]=>1[filter]=>raw])检查update@NancyOh没错。谢谢!谢谢!Thanx的回复,我尝试了这个,错误消失了。但是我现在看不到任何品牌名称。有什么建议吗?Thanx@Nancy:print\r($brands)
在循环之前使用此选项并共享结果,这样做的结果是Brend:Array([0]=>WP\U术语对象([Term\U id]=>65[name]=>Nokia[slug]=>Nokia[Term\U group]=>0[Term\U taxonomy\U id]=>65[taxonomy]=>product\U brand[description]=>0[parent]=>0[count]=>1[filter]=>raw][1]=>WP\U术语对象([Term\U id]=>66[名称]=>三星[slug]=>三星[term_group]=>0[term_分类法\u id]=>66[taxonomy]=>产品品牌[description]=>0[parent]=>0[count]=>1[filter]=>raw))检查update@NancyOh是的。谢谢!请在
中添加$brand->name。好的,谢谢@devpro。现在很好:)是的,现在很好:)我投你的票:)ookk它的聪明工作:请在
中添加$brand->name。现在很好:)是的,现在很好:)我投你的票:)ookk它的聪明工作:P
<?php $brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") );
echo "Brend: ";
foreach( $brands as $brand ) {
$url = get_term_link( $brand->slug, 'product_brand' );
echo '<a href="' . $url . $brand->name .'">'.$brand->name.'</a>';
}?>