【问题标题】:PHP Wordpress string concatenation not workingPHP Wordpress字符串连接不起作用
【发布时间】:2017-11-23 07:42:32
【问题描述】:

以下内容:

class="<?php the_field('icon','service-category_'.$term->term_id) ?>">

成功了:

class="icon-ico-1"

但是当我执行以下操作时:

<?php $iconpath = 'images/'.the_field('icon','service-category_'.$term->term_id).'.svg.php'; ?>

它不计算'icon-ico-1',而是给出以下路径:

images/.svg.php

这显然是不正确的。我希望它是:

images/icon-ico-1.svg.php

【问题讨论】:

  • 日志中有错误吗?好像您在 the_field() 函数未正确定义的地方使用它。这两个示例是同一个文件/同一个范围吗?

标签: php html wordpress string svg


【解决方案1】:

尝试将您的字段存储为变量并回显字符串

<?php 
  $icon = get_field('icon');
  $servicecategory = get_field('service-category_');
  $newterm = $term->term_id;
  
  echo 'images/'.$icon.'-'.$servicecategory.'-'.$newterm;
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-24
    • 2021-01-26
    • 2018-09-03
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    相关资源
    最近更新 更多