2016-05-15 82 views
0

我正在創建一個包含多個頁面的網站..我添加了必須向每個頁面添加META標籤,但是我想知道是否有我們提取東西的方法從現有的標籤,並將其添加到其他標籤。自動從其他meta標籤填充meta標籤

因此,例如這些標籤已經存在於靜態的HTML頁面:

<meta name="description" content="Description 01"/> 
<title>Title 01</title> 

現在任何方式來提取每一頁這些值並插入其他標籤到其他頁面。

所以首頁就已經包含:

<meta name="description" content="Description Home"/> 
<title>Title Home</title> 

而這些將被自動添加:

<meta itemprop="name" content="Title Home"> 
<meta itemprop="description" content="Description Home"> 
<meta name="twitter:title" content="Title Home"> 
<meta name="twitter:description" content="Description Home"> 
<meta property="og:title" content="Title Home" /> 
<meta property="og:description" content="Description Home" /> 

和接觸頁將已經包含:

<meta name="description" content="Description Contact"/> 
<title>Title Contact</title> 

這些會自動添加:

<meta itemprop="name" content="Title Contact"> 
<meta itemprop="description" content="Description Contact"> 
<meta name="twitter:title" content="Title Contact"> 
<meta name="twitter:description" content="Description Contact"> 
<meta property="og:title" content="Title Contact" /> 
<meta property="og:description" content="Description Contact" /> 
+0

你如何服務你的網頁? Apache的? Tomcat的?基本上,你必須通過某種中間件發送你所有的靜態頁面。 –

+0

*「從每個頁面提取這些值」*是什麼意思?一點也不清楚你想要做什麼,在哪裏或什麼數據源真的是 – charlietfl

+0

@Aaron_H Apache。 – ddshd

回答

0

讓它動態而不是

創建的header.php然後將下面的代碼

<!DOCTYPE html> 
<html> 
    <head> 
     <meta name="description" content="<?php echo $page_desc ?>"/> 
     <title><?php echo $page_title ?></title> 
     <meta itemprop="name" content="<?php echo $page_title ?>"> 
     <meta itemprop="description" content="<?php echo $page_desc ?>"> 
     <meta name="twitter:title" content="<?php echo $twt_title ?>"> 
     <meta name="twitter:description" content="<?php echo $twt_desc ?>"> 
     <meta property="og:title" content="<?php echo $og_title ?>" /> 
     <meta property="og:description" content="<?php echo $og_desc ?>" /> 
    </head> 
    <body> 

創建footer.php然後將下面的代碼

</body></html> 

創建index.php爲第一頁

<?php 
    // the page title and description should be declared first before you include the header and footer 
    $page_title = 'My Page Title'; 
    // same as the others 
    $twt_title = $page_title; 
    $og_title = $page_title; 

    $page_desc = 'My Page Description'; 
    // same as the others 
    $twt_desc = $page_desc; 
    $og_desc = $page_desc; 

    include 'header.php'; 
?> 
<!-- some page contents --> 
<?php include 'footer.php'; ?> 

創建about.php作爲另一頁

<?php 
    // the page title and description should be declared first before you include the header and footer 
    $page_title = 'About us'; 
    // same as the others 
    $twt_title = $page_title; 
    $og_title = $page_title; 

    $page_desc = 'My Page Description'; 
    // same as the others 
    $twt_desc = $page_desc; 
    $og_desc = $page_desc; 

    include 'header.php'; 
?> 
<!-- some page contents --> 
<?php include 'footer.php'; ?>