亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 函數返回 ="" 而不是 /

PHP 函數返回 ="" 而不是 /

PHP
RISEBY 2021-11-26 14:42:16
我有一個 wordpress 實例,我想通過 php 函數設置內聯 html 標簽的背景圖像。html是:<div id="content" class="site-content" <?php echo get_background_for_single(get_the_ID(), is_single()); ?>>上面的 html 和 php 在瀏覽器中有以下輸出:<div id="content" class="site-content" style="background-image: url(" http:="" localhost="" wiese="" wp-content="" uploads="" 2019="" 06="" test.jpg");="">在functions.php我得到:function get_background_for_single($ID, $single) {    if ($single == 1) {        return 'style="background-image: url("' . get_the_post_thumbnail_url($ID) . '");';    }}如果我按如下方式控制段落中的輸出,則顯示正確:<p><?php echo get_background_for_single(get_the_ID(), is_single()); ?><p>它以 ap 標簽返回:style="background-image: url("http://localhost/wiese/wp-content/uploads/2019/06/test.jpg");為什么函數返回“=”而不是“/”?也許這是一個轉儲錯誤,但我看不到我的錯誤。
查看完整描述

1 回答

?
DIEA

TA貢獻1820條經驗 獲得超2個贊

將我的功能更改為以下是解決方案:


function get_background_for_single($ID, $single) {


    if ($single == 1) {

        return 'style="background-image: url(&quot;' . get_the_post_thumbnail_url($ID) . '&quot;);"';

    }

}


查看完整回答
反對 回復 2021-11-26
  • 1 回答
  • 0 關注
  • 200 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號