porcelanosa / yii2-seo-attributes
用于设置SEO属性的Yii2扩展
dev-master
2016-07-24 11:19 UTC
Requires
- php: >=5.4.0
- kartik-v/yii2-tabs-x: *
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-26 02:18:57 UTC
README
警告!此包正在开发中
yii2-seo-attributes
Yii2扩展,用于添加SEO属性,如标题、元键、元描述等【安装】
composer require porcelanosa/yii2-seo-attributes
运行迁移
$ php yii migrate/up --migrationPath=@vendor/porcelanosa/yii2-seo-attributes/migrations
在模型类中添加行为
'seoBehavior' => [ 'class' => SeoBehavior::className(), 'model_name' => $this::className(), 'uploadPath' =>'@web/uploads/seoimage/' ],
在配置中添加模块
'modules' => [ ... 'seo' => [ 'class' => 'porcelanosa\yii2seo\Module', 'uploadPath' =>'@web/uploads/seoimage/' ], ... ]
在管理视图中
echo \porcelanosa\yii2seo\SeoWidget::widget( [ 'model' => $model, 'form' => $form, 'behaviorName' => 'seoBehavior', 'templateType' => 'minimum-minimorum' // 'minimal', 'standart', 'full' ] );
##使用
$this->title = $model->seo->title;
或元标签
$this->registerMetaTag([ 'name' => 'description', 'content' => $model->seo->meta_descr] );
或在控制器动作中
if ($model->seo) { // page title $this->getView()->title = $model->seo->title; // meta keywords $this->getView()->registerMetaTag([ 'name' => 'description', 'content' => $model->seo->meta_descr, ]) ; }
##社交元标签使用示例
https://moz.com/blog/meta-data-templates-123
或
http://www.iacquire.com/blog/18-meta-tags-every-webpage-should-have-in-2013
Twitter Card 文档
https://dev.twitter.com/cards/overview
Open Graph 文档
https://developers.facebook.com/docs/opengraph/getting-started
Google Schema.org 文档
https://developers.google.com/+/web/snippet/
Schema.org 类型
http://schema.org/docs/schemas.html
模板类型
扩展提供模板类型:'only2', 'minimum', 'standart', 'full'