Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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
在两个php文件之间传递值_Php_Html_Css_Wordpress - Fatal编程技术网

在两个php文件之间传递值

在两个php文件之间传递值,php,html,css,wordpress,Php,Html,Css,Wordpress,我有我的wordpress页面,我想在header.php和style.php(style.css的php版本)文件之间传递值 在header.php中,我有: <?php $background = get_field('background')['url']; ?> 检索自定义字段值(上传的img url) 在my style.php中,我有css,但在此之前,我有标记,可以在其中定义一些在样式表中使用的变量。有什么想法吗?如何从header.php检索该值并将其存储在st

我有我的wordpress页面,我想在header.php和style.php(style.css的php版本)文件之间传递值

在header.php中,我有:

<?php $background = get_field('background')['url']; ?>

检索自定义字段值(上传的img url)

在my style.php中,我有css,但在此之前,我有
标记,可以在其中定义一些在样式表中使用的变量。有什么想法吗?如何从header.php检索该值并将其存储在style.php上的变量中


非常感谢您提供的任何帮助。

如果我没有弄错,您基本上希望在CSS中对背景图像有更多的控制,但需要能够允许后端的用户控制来定义它

在这种情况下,我会在
header.php中做一些简单的事情,比如

<style>
.background {
   background-image: url("<?php echo $background ?>");
}
</style>
如果试图定义全局变量,请将其置于变量上方:


然后,您可以在任何其他页面上使用$background(但如果在页眉中使用$background,则其他页面上已经可以访问它,因为这是模板的一部分)。

回答您提出的问题,而不是您遇到的问题

您可以使用:


如果要通过单个标记计算$\u GET和$\u POST变量 在混合中不包括$\u COOKIE,使用$\u服务器['REQUEST\u METHOD'] 为了确定所使用的方法并相应地设置开关块, e、 g:


发件人:


您不能使用会话在文件之间传递信息吗?我不确定wordpress是如何处理会话的,但会话是将数据从一个文件传递到另一个文件的唯一方式。您好,谢谢您的建议,这不是一个真正的选项,因为我忘了提到有两个图像必须根据一些媒体查询显示。而且,将我所有的查询都放在标题部分似乎不是一个合适的解决方案。无论如何,你在其他情况下的想法太棒了!:)你不需要头脑中的疑问。您可以在CSS中添加其他样式。使用内联样式作为CSS的基本“附加”。
   <style>
      .background {
          background-image:url(<?php the_field('background_image')?>);
       }
   </style>
<div class="background">
Content goes here
</div>
    .background {
      background-size: cover;
      background-position: center center;
      height: 600px;
    }
    @media only screen and (max-width: 40em){
        .background {
          height: 400px;
        }
     }
<?php

$_GET['foo'] = 'a';
$_POST['bar'] = 'b';
var_dump($_GET); // Element 'foo' is string(1) "a"
var_dump($_POST); // Element 'bar' is string(1) "b"
var_dump($_REQUEST); // Does not contain elements 'foo' or 'bar'

?>
<?php

switch($_SERVER['REQUEST_METHOD'])
{
case 'GET': $the_request = &$_GET; break;
case 'POST': $the_request = &$_POST; break;
.
. // Etc.
.
default:
}
?>