Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在functions.php中声明内联背景图像_Php_Jquery_Html_Css_Wordpress - Fatal编程技术网

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

在functions.php中声明内联背景图像,php,jquery,html,css,wordpress,Php,Jquery,Html,Css,Wordpress,我不确定这是否可以做到,因为无论我如何努力,我都找不到任何东西来帮助我。我正在使用Ajax在按下按钮时加载到in posts。加载的帖子由myfunctions.php中的my函数格式化。所有这些都能很好地工作,我遇到的问题是背景图像:属性需要是内联css,以便它可以从我的自定义字段中提取图像。然而,这一切在模板文件中都可以完美地工作。无论我尝试什么,php都会拒绝我的内联样式作为背景图像 以下是我的If声明的全部内容: if ($loop -> have_posts()) : whil

我不确定这是否可以做到,因为无论我如何努力,我都找不到任何东西来帮助我。我正在使用
Ajax
在按下按钮时加载到in posts。加载的帖子由my
functions.php中的my函数格式化。所有这些都能很好地工作,我遇到的问题是
背景图像:
属性需要是
内联css
,以便它可以从我的自定义字段中提取图像。然而,这一切在模板文件中都可以完美地工作。无论我尝试什么,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);
有人知道我哪里出了问题吗?

if($\u SESSION[“load\u type”]==“product”){
if ($_SESSION["load_type"] == 'product'){    
    $image = the_field(product_image);           
    $out .= '<div class="small-6 large-3 columns">
                <div class="small-6 large-12 columns end no-pad morepro" style="background-image: url('"'.$image.'"')">
                   <a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
               </div>
               <h2 class="product-load">'.get_the_title().'</h2>
           </div>';

}
$image=_字段(产品_图像); $out.=' “.获取标题() '; }
如果($_SESSION[“load_type”]=“product”){ $image=_字段(产品_图像); $out.=' “.获取标题() '; } 并查看它是否有效

更改以下内容

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

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

  • 您的“产品图像”是自定义大小(如果它是常量,请使用它而不加引号)-或者编辑您的问题并解释它是什么
  • 函数需要“返回”值,而不是回显它。我之所以提到这一点,是因为wordpress codex通常使用“the_something()”函数不会返回值,它只会显示一些内容。如果你想返回一个值,它通常是“get_the_something()”。这很重要,因为它会破坏json对象(如果您在js端使用的是json对象) 例如:vs,或vs等
  • 背景图像中的引号应该是可选的。

    更改以下内容

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

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

  • 您的“产品图像”是自定义大小(如果它是常量,请使用它而不加引号)-或者编辑您的问题并解释它是什么
  • 函数需要“返回”值,而不是回显它。我之所以提到这一点,是因为wordpress codex通常使用“the_something()”函数不会返回值,它只会显示一些内容。如果你想返回一个值,它通常是“get_the_something()”。这很重要,因为它会破坏json对象(如果您在js端使用的是json对象) 例如:vs,或vs等

  • 背景图像中的引号应该是可选的。

    否我在日志中获取此引号
    未捕获错误:语法错误,无法识别的表达式:http://fireproductsearch.com/dev/wp-content/uploads/2015/08/3112011122511-a….jpghttp://fireproductsearch.com/dev/wp-content/uploads/2015/08/Propak.jpg                                                                                           
    什么是“产品图像”?这是变量吗?如果是,请在前面放置$。从引用问题的角度来看,这个答案很好。这会让整个网站崩溃,并给我们一个白色的屏幕。产品图片是恒定的,我想我没有得到这个我的日志
    Uncaught Error:Syntax Error,无法识别的表达式:http://fireproductsearch.com/dev/wp-content/uploads/2015/08/3112011122511-a….jpghttp://fireproductsearch.com/dev/wp-content/uploads/2015/08/Propak.jpg                                                                                           
    什么是“产品图像”?这是变量吗?如果是,请在前面放置$。从引用问题的角度来看,这个答案很好。这会让整个网站崩溃,并给我们一个白色的屏幕。产品图片是固定的,我想谢谢你的帮助,但它仍然会在日志
    Uncaught Error:Syntax Error,无法识别的表达式:http://fireproductsearch.com/dev/wp-content/uploads/2015/08/4165880_scbaspa…http://fireproductsearch.com/dev/wp-content/uploads/2015/08/airxpress2.jpg 			                
    我已经弄清楚了它在做什么,ajax在4篇文章中加载,当我们将背景图像放入,它将所有4篇文章中的图像URL拉到一行中,为什么我没有提到ideaAs,您需要获取变量而不是显示它。在返回内容之前,您正在回显图像变量。为了让它工作,你需要有一个功能,它将“返回”产品图像,而不是回显它。在你正在使用的插件中是否有名为“get_the_field”或类似的功能。以上答案更为正确。在使用“the_field()”函数的地方,您需要使用返回值而不是显示值的函数(或者使用输出缓冲函数只是为了获取我根本不推荐的变量)您正在使用哪个插件?我的意思是,使用“the_field()”函数的插件是什么?谢谢你,在你的帮助下,最终我们得到了它,需要像这样
    style=“background image:url('.get_field(“product_image”,false,true)。”)“
    谢谢你的帮助,即使我很沮丧,感谢您的帮助,但它仍然会在日志
    Uncaught Error:Syntax Error,unrecogned expression:http://fireproductsearch.com/dev/wp-content/uploads/2015/08/4165880_scbaspa…http://fireproductsearch.com/dev/wp-content/uploads/2015/08/airxpress2.jpg 			                
    我已经知道它在做什么,ajax在4篇文章中加载,当我们将背景图像放入时,它将所有4篇文章中的图像URL拉到一行中,为什么这样做我没有提到ideaAs,您需要获取变量而不是显示它。在返回内容之前,您正在回显图像变量。为了让它工作,你需要有一个功能,它将“返回”产品图像,而不是回显它。你有“获取字段”之类的函数吗