PHP / Wordpress - 在Echo中包含IF函数 [英] PHP/Wordpress - Including an IF function inside an Echo

查看:646
本文介绍了PHP / Wordpress - 在Echo中包含IF函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下WordPress查询:

I have the following WordPress query:

$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
    echo '<div class="' . $tax_term->slug . '" style="display:none; background:url(' . $whatdoiputhere . ');">';
    while ($my_query->have_posts()) : $my_query->the_post();

在后台URL中,我需要包含一个由以下代码生成的图像URL:

In the background URL, I need to include an image URL that is generated by the following code:

<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>

如何在后台网址中包含此IF函数?

How would I include this IF function inside the background URL?

我试过这个,但你可以猜测它不起作用:

I tried this but as you can guess it didn't work:

background:url(' . if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); . ');

对于我将如何做到这一点,我将不胜感激。

Would appreciate some help as to how I would do this.

推荐答案

<?php
    if (function_exists('z_taxonomy_image_url')) $background_url = 'background:url(' . z_taxonomy_image_url() . ')';
    echo '<div class="' . $tax_term->slug . '" style="display:none; ' . $background_url . '">';
?>

这篇关于PHP / Wordpress - 在Echo中包含IF函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆