在functions.php中声明内联背景图像

上瘾的

我不确定是否可以做到这一点,因为无论我多么努力,都找不到任何可以帮助我的东西。Ajax习惯在按下按钮时其加载到帖子中。所加载的帖子由我的内的我的函数格式化functions.php一切正常,我要解决的问题是background-image:属性必须是属性,inline css以便它可以从我的自定义字段中提取图像。但是,所有这些都可以在模板文件中完美地工作。不管我尝试什么,无论我尝试什么,都会functions.php拒绝我的内联样式作为背景图像。

这是我全部的If语句:

if ($loop -> have_posts()) :  while ($loop -> have_posts()) : $loop -> the_post();


        if ($_SESSION["load_type"] == 'home')
        {
                $out .= '<div class="small-6 large-3 columns end thumb">
                            <div class="grid">
                                <figure class="effect-zoe">
                                    '.get_the_post_thumbnail( get_the_ID(), $size, $attr ).'
                                    <figcaption>    
                                        <h2>'.get_the_title().'</h2>
                                        <hr class="light">
                                        <p class="description">'.get_the_content().'</p>
                                    </figcaption>           
                                </figure>
                            </div>
                        </div>';        
        }

        else

        if ($_SESSION["load_type"] == 'category')

        {



                $out .= '<div class="small-6 large-6 columns end thumb under">
                            <div id="case">

                                <div class="th" id="element" >
                                    <a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
                                </div>
                            </div>


                            <div class="brief">
                                <a href="'. get_permalink($post->ID) .'">'.get_the_title().'</a>    
                                <p class="suppy">Supplier</p>
                                <p>'.get_the_excerpt().'</p>
                                <a class="more-btn" href="'. get_permalink($post->ID) .'">More</a>
                            </div>                  
                        </div>';
        }

        else

        if ($_SESSION["load_type"] == 'product')

        {               
                $out .= '<div class="small-6 large-3 columns">
                            <div class="small-6 large-12 columns end no-pad morepro" style="background-image: url(''.the_field(product_image).'')">
                                <a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
                            </div>
                            <h2 class="product-load">'.get_the_title().'</h2>
                        </div>';

        }


    endwhile;
    endif;
    wp_reset_postdata();
    die($out);

这就是我遇到的麻烦部分,每次我尝试加载到网站时都会崩溃整个网站 background-image:

if ($_SESSION["load_type"] == 'product')

    {               
            $out .= '<div class="small-6 large-3 columns">
                        <div class="small-6 large-12 columns end no-pad morepro" style="background-image: url(' '.the_field(product-image).' ')">
                            <a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
                        </div>
                        <h2 class="product-load">'.get_the_title().'</h2>
                    </div>';

    }


enter code here

谁能看到我要去哪里错了?

凉爽的

改变以下

style="background-image: url(' '.the_field(product-image).' ')"

进入

style="background-image: url('.the_field("product-image").')"

这在以下情况下应该有效:

  1. 您的“产品图片”是自定义尺寸(如果使用它时不加引号,则为常量)-或编辑您的问题并解释它的含义。
  2. the_field()函数需要“返回”值而不回显它。我之所以这样说是因为Wordpress Codex通常使用“ the_something()”函数不会返回值,而只会显示某些内容。如果要返回值,则通常为“ get_the_something()”。这很重要,因为它将破坏您的json对象(如果这是您在js端使用的对象)例如:the_content() vs get_the_content()get_the_title() vs the_title()等...

内背景图片行情应该是可选

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

div 标签中的背景图像大小 - 全屏 - 内联 css

来自分类Dev

在 .php 文件中设置背景图像

来自分类Dev

背景图像拉伸的内联样式

来自分类Dev

内联 PHP If 语句返回背景图像样式之外的 url

来自分类Dev

我可以在CSS中声明2个背景图像但不能同时声明吗?

来自分类Dev

设置内联背景图像时保留 CSS 背景属性

来自分类Dev

是否可以在style.css中内联SVG作为背景图像进行多次重用?

来自分类Dev

如何添加背景图像内联样式以链接标签Rails

来自分类Dev

如何获得内联SVG代码作为背景图像?

来自分类Dev

尝试使用内联 css 设置背景图像

来自分类Dev

PIL从图像中删除背景图像

来自分类Dev

在PHP中使用背景图像

来自分类Dev

在PHP中使用背景图像

来自分类Dev

使用php设置背景图像

来自分类Dev

致命错误:无法在functions.php第25行中重新声明session_start()

来自分类Dev

Winforms中未显示背景图像

来自分类Dev

Mailchimp中的可编辑背景图像

来自分类Dev

<div>中的背景图像不显示

来自分类Dev

chrome中的bxSlider背景图像闪烁

来自分类Dev

jQuery中的背景图像实际大小

来自分类Dev

烧瓶中未显示背景图像

来自分类Dev

在Flutter中清除背景图像

来自分类Dev

在xmonad中设置背景图像

来自分类Dev

DIV中的背景图像未显示?

来自分类Dev

gwt中的动态css背景图像

来自分类Dev

背景图像未在Div中显示

来自分类Dev

背景图像:未在 CSS 中显示

来自分类Dev

flex 容器中的 CSS 背景图像

来自分类Dev

检测白色背景图像中的轮廓