使用php动态添加meta标签

发布于 2024-09-05 13:33:33 字数 176 浏览 3 评论 0原文

在我的网站中,我有一个类别列表,我必须为它们添加元关键字和描述。我有一个页面,我将从数据库中检索类别。

谁能告诉我如何更简单地为所有类别添加元标记。

问候, 雷卡 http://hiox.org

In my site I have a list of categories and I have to put meta keywords and description for them.I have a single page where I will retrieve the categories from the database.

Can anyone tell me how to make this much simpler to put meta tags for all the categories.

Regards,
Rekha
http://hiox.org

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你好,陌生人 2024-09-12 13:33:33

我不确定这是否是您正在寻找的,但是...

我创建了一个简单的脚本,用于使用从数组中获取的随机关键字动态填充元关键字。

将其放入模板文件的标题中。

<meta name="keywords" content="<?php get_keywords()?>" />

这将从关键字数组中创建一个以逗号分隔的不超过 10 个关键字的列表。如果您想避免每次都进行数据库查询,您可以为每个类别硬编码可能的关键字数组。如果您不介意查询,可以将数组替换为返回数组的查询。

function get_keywords(){
    $keywords=array('keyword1','keyword2','keyword3','keyword4','keyword5');
    if (count($keywords)<10)
        $max=count($keywords);
    else
        $max=10;
    $rand_keys = array_rand($keywords, $max);
    foreach($rand_keys as $vals){
        $keyword[]=$keywords[$vals];
    }
    echo implode(", ", $keyword);
}

希望这有帮助。

I'm not sure if this is what you are looking for but...

I have a simple script I created to dynamically populate the meta keywords with random keywords taken from an array.

Put this in the header of your template file.

<meta name="keywords" content="<?php get_keywords()?>" />

This will create a comma delimited list of no more than 10 keywords from an array of keywords. If you wanted to avoid a database query each time you could hard-code arrays of possible keywords for each category. If you don't mind a query, you could replace the array with a query which returns an array.

function get_keywords(){
    $keywords=array('keyword1','keyword2','keyword3','keyword4','keyword5');
    if (count($keywords)<10)
        $max=count($keywords);
    else
        $max=10;
    $rand_keys = array_rand($keywords, $max);
    foreach($rand_keys as $vals){
        $keyword[]=$keywords[$vals];
    }
    echo implode(", ", $keyword);
}

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文