【问题标题】:cakephp: how to make title and metas unique to each page?cakephp:如何使每个页面的标题和元数据唯一?
【发布时间】:2015-01-01 12:25:13
【问题描述】:

我有一个用 cakephp 2.2 制作的项目

它使用 default.ctp 布局,其中

<title>, <meta> are harde coded 

所以我网站的每个页面都有相同的标题和元数据

我的目标(对于 SEO)是使每个页面的标题和元数据独一无二(每个控制器)

实现这一目标的最佳方法是什么?

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    使用Extending Views

    <?php
    // in your view file
    $this->assign('title', 'best title');
    
    $this->start('meta');
    echo $this->Html->meta('keywords', 'enter any meta keyword here');
    $this->end();
    ?>
    
    // in your layout file (default.ctp)
    <!DOCTYPE html>
    <html lang="en">
        <head>
        <title><?php echo $this->fetch('title'); ?></title>
        <?php echo $this->fetch('meta'); ?>
        </head>
        // rest of the layout follows
    

    【讨论】:

      猜你喜欢
      • 2014-11-20
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      相关资源
      最近更新 更多