我有一个php文件,上面有一堆php,然后:
$title2="stevea";
get_header();
?>
<!-- Display the form -->
<body>get_header()引入的头文件是
<?php
/**
* Header Template
*
* Here we setup all logic and XHTML that is required for the header section of all screens.
*
* @package WooFramework
* @subpackage Template
*/
$title="qwerty";
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php echo esc_attr( get_bloginfo( 'charset' ) ); ?>" />
<title><?php echo $title ?> | <?php echo $title2 ?></title> 当页面加载时,源代码显示
<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8" />
<title>qwerty | </title> 因此,在header.php ($qwerty)中定义的PHP变量被<title>行找到并求值,但是在调用get_header()之前定义的PHP变量($stevea)没有被找到并求值。
有人知道这是怎么回事吗?
发布于 2016-04-18 03:57:11
@Samir,
是的,我就是这么解决的。这些变量来自元数据,所以在header.php中,我用以下命令重新读取它们:
$meta = get_post_meta($ID);
$meta = array_map(function($n) {return $n[0];}, $meta);
$product_title=$meta['product_title'];
$barcode_number=$meta['barcode_number'];现在我可以写:
<title><?php echo $product_title ?> Barcode <?php echo $barcode_number ?></title> 正确的数据就会被插入。
https://stackoverflow.com/questions/36671570
复制相似问题