输出变量为html而不是字符串-PHP

时间:2020-04-08 07:25:05

标签: php html css wordpress

我正在Wordpress网站上工作。这是我的functions.php中的代码:

add_filter( 'listify_get_listing_to_array', function( $data, $listing ) {
    $cert = $listing->get_object()->_job_certificates;
    $desc = $listing->get_object()->_job_description;
    $price = $listing->get_object()->_job_price;
    $duration = $listing->get_object()->_trajanje_casa;
    $duration2 = $listing->get_object()->_job_duration;
  // Only add if our custom field is not empty.
  if ( '' !== $cert ) {
    $data['cert'] = $cert;
  }
  if ( '' !== $desc ) {
    $data['desc'] = $desc;
  }
  if ( '' !== $price ) {
    $data['price'] = $price;
  }
  if ( '' !== $duration ) {
    $data['duration'] = $duration;
  }
  if ( '' !== $duration2 ) {
    $data['duration2'] = $duration2;
  }

  // Return modified list of data.
  return $data;
}, 10, 2 );

add_action( 'listify_content_job_listing_meta', function() {
  // Check if available.

  //price/duraton
  echo '<# if ( data.duration && !data.duration2) { #>';

  echo '<div class="job_price_duration"><p><span class="job_price">{{data.price}}</span> / <span class="job_duration">{{data.duration}}</span></p></div>';

  echo '<# } #>';

  echo '<# if ( data.duration2 && !data.duration ) { #>';

  echo '<div class="job_price_duration"><p><span class="job_price">{{data.price}}</span> / <span class="job_duration">{{data.duration2}}</span></p></div>';

  echo '<# } #>';

  //certificate
  echo '<# if ( data.cert ) { #>';

  echo '<div class="job_certificates"><p>{{data.cert}}</p></div>';

  echo '<# } #>';

  //bio
  echo '<# if ( data.desc && !data.cert ) { #>';

  echo '<div class="job_description"><p>{{data.desc}}</p></div>';

  echo '<# } #>';

} );

以html格式输出的变量如下:

  echo '<div class="job_certificates"><p>{{data.cert}}</p></div>'; 

显示字符串而不是html。因此,例如,如果我的变量(data.cert)是实际的html,它将把它呈现为不正确的字符串。看截图: enter image description here

关于如何将输出作为html而不是字符串的任何建议?

谢谢!

0 个答案:

没有答案
相关问题