如何将page的值用于php中other的元标记


How to use the values of page for the meta tag of other in php ?

我有两个页面,内容是动态馈送的,第一个index.php包括另一个页面person.php,当我点击链接时:

index.php:

<?php include("db1.php");
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
$pages=array(
                 "person"=>"person.php"

                 ); 
?>
<!DOCTYPE html>
<head>
<title>Untitled Document</title>
<meta property="og:title" content=""/>
    <meta property="og:url" content=""/>
    <meta property="og:site_name" content=""/>
    <meta property="og:description" content=""/>
</head>
<body>
<?
    $sql="select id, name,title,image from persons  where cat =10 ";
    $rs=mysql_query($sql)or die(mysql_error());
    if(list($id,$name,$title,$image)=mysql_fetch_array($rs)){
        ?>
<a href="?page=person&p=<? echo $id;?>" id="<? echo $id;?>" class="details">
<?
    }
    ?>
<div class="twelve columns" id="persons">
        <?
if($_GET["page"]=="")
                    $p="persons1";
                else
                    $p=$_GET["page"];
                if($pages[$p]!="")
                    include($pages[$p]);
                else
                    echo "page not found ";
                    ?>
                  </div>
</body>
</html>

第2页:person.php:

<? include("db1.php");?>
<?php
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
?>
<div class="row">
    <div class="twelve columns">
        <div class="eight columns">
    <?
    if(isset($_GET['p'])){
$id=str_replace('-',' ',(string)$_GET['p']);
$name1="";
    $sql="select id, name,title,details,image,cat from persons  where name ='".$id."' order by name asc";
    $rs=mysql_query($sql)or die(mysql_error());
    if(list($id,$name,$title,$details,$image,$cat)=mysql_fetch_array($rs)){
        $a=$name;
  ?>
    <h3><? echo $name;?></h3>
    <h5><? echo $title;?></h5>
    <p align="justify">
        <img alt="<? echo $name;?>" src="images/persons/<? echo $image?>" title="<? echo $name;?>" style="float:right; margin-left:15px;" />
        <? echo $details;?>
    </p>
    <?
    }
    }
?>

当页面被包含时,如何在index.php的元标签中使用person.php页面的值?

您可以使用php全局关键字声明要使用的变量,以在两个文件中定义变量。有关详细信息,请参见此处:http://us3.php.net/manual/en/language.variables.scope.php

然而,使用类似的通用名称($name、$title、$details、$image)必然会导致冲突,尤其是在Wordpress环境中。您最好的选择是选择一个唯一的变量名,将其声明为数组,并将其中每个项设置为元素:

 global $amer_enaya_fb_metadata;
 $amer_enaya_fb_metadata = array( 'name' => $name, ... );