English 中文(简体)
基于 URL 生成动态元标签
原标题:Generate dynamic meta-tags based on URL

我试图为每页设计 动态独家超导元牌:

i.e: url.com/index.php?action=signup

页眉 - 签名标题

关键字 - 签名元元

描述 - 签名描述

url.com/index.php? action= about

页眉 - 关于标题

关键字 - 关于元元关键字

描述 - 关于描述

你说的对

我使用阵列... 但不知道如何将每个阵列派到每一页

<强度 > CONF.PHP

<?php
$metas = array( 
 index.php  => array( 
 header  =>  Home Title , 
 keywords  =>  Home Meta Keywords , 
 description  =>  Home Meta Description  
), 
 signup  => array( 
 header  =>  Signup Title , 
 keywords  =>  Signup Meta Keywords , 
 description  =>  Signup Meta Description  
), 
 about  => array( 
 header  =>  About Title , 
 keywords  =>  About Meta Keywords , 
 description  =>  About Meta Description  
) 
);
?>

< 强 > INDEX.PHP

<TITLE><?php echo $metas[ title ]; ?></TITLE>
<meta name="description" content="<?php echo $metas[ description ]; ?>" >
<meta name="keywords" content="<?php echo $metas[ keywords ]; ?>" >

如何在每页上标注这些价值?

最佳回答

你们在正确的轨道上:-)

这样做的方式如下:

<TITLE><?php echo $metas[ index.php ][ title ]; ?></TITLE>

您可以从 $_SERVER 超级全球数组/变量获得脚本名称 。

另外,从您的 config.php 文件中删除最后三行, 您不需要它们 。

祝你好运,与 PHP 一起确保您对与阵列玩耍有良好的知识。 这是关键 。

编辑:

$page =  index.php ;
if ( isset( $_GET[ action ] ) && $_GET[ action ] != "" )
{
    $page = $_GET[ action ];
}

<TITLE><?php echo $metas[$page][ title ]; ?></TITLE>

编辑: (on 27th May 2012)

我认为这几乎就是一切:

您在配置.php 中的代码

<?php

$meta[ INDEX ][ title ] = "Home page";
$meta[ INDEX ][ keywords ] = "kwd1, kwd2, kwd3";
$meta[ INDEX ][ description ] = "Home description";

$meta[ SIGNUP ][ title ] = "Sign up..!";
$meta[ SIGNUP ][ keywords ] = "kwd1, kwd2, kwd3";
$meta[ SIGNUP ][ description ] = "Sign up description";

$meta[ ABOUT ][ title ] = "About Company";
$meta[ ABOUT ][ keywords ] = "kwd1, kwd2, kwd3";
$meta[ ABOUT ][ description ] = "About company description";

您在任何应用程序页面/屏幕中的代码 (.php 文件) :

<?php

include "config.php";

// Choice 1: if you want to specify page hardcoded at each page then you can say $page =  ABOUT  for about-us page and $page =  INDEX  for home page etc.
$page =  ABOUT ;
if( strtoupper($_SERVER[ REQUEST_URI ], $page) !== false )
{
    $title = $meta[$page][ title ];
    $keywords = $meta[$page][ keywords ];
    $description = $meta[$page][ description ];
}
// Now you have your meta - use it the way you want
echo $title;

// Choice 2: If you want to make it little more dynamic
// Here you don t need to define any hardcoded variable at page level as everything will be considered from the URL being requested
$page_index = array_keys($meta);

foreach($page_index as $page)
{

    if ( strpos( strtoupper($_SERVER[ REQUEST_URI ]), $page ) !== false)
    {
        $title = $meta[$page][ title ];
        $keywords = $meta[$page][ keywords ];
        $description = $meta[$page][ description ];
        break;
    }
}
// Now you have your meta - use it the way you want
echo $title;

?>
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签