Joomla下载组件Docman的”文档信息”页面的Title的改变 (SEO for com_docman)
在Docman的下载页面中,有个"文档信息"或者"文件细节"的页面(值为_DML_TPL_TITLE_DETAILS)
这个页面的作用就是显示下载文件的所有详细信息的,文件大小,文件类型等等…
但是文件的标题缺不太人性化,如 文档信息 – 本站下载 , 这样的话,读者浏览是没什么问题…但是搜索引擎浏览的话,页面title都是一致的…而且没有关键字…那可能就是个大问题了..很不友好
通过本文可以改变为这样,如 源代码 – 资源下载 – 本站下载 , 演示页面: 打开
当前,可以把文件详细信息的任何一个内容提取出来,放在TITLE中
我们开始:
找到 components/com_docman/themes/mjaztools_blogtheme/templates 中的 page_docdetails.tpl.php
注: 我使用的是 mjaztools_blogtheme 的模版,这里就选择你的模版吧,详情请查看 这里
先看一下这个文件:
<?php
//添加本页标题
$this->splugin('pagetitle', _DML_TPL_TITLE_DETAILS );
?>
<?php
//加载CSS
echo $this->plugin('stylesheet', $this->theme->path . "css/theme.css");
?>
<?php
//菜单
echo $this->html->menu;
?>
<h2 id="dm_title">
<?php
//输出"文档信息"或"文件细节"字样
echo _DML_TPL_TITLE_DETAILS;
?>
</h2>
<?php
//输出表格
echo $this->html->docdetails;
?>
好的,我们就是要修改 "添加本页标题" 的语句,恩,怎么提取文件细节呢?文档中其实已经给出了
General variables :
* $this->theme->path (string) : template path
* $this->theme->name (string) : template name
* $this->theme->conf (object) : template configuartion parameters
* $this->theme->icon (string) : template icon path
Preformatted html variables :
* $this->html->docdetails (string)(fetched from : documents/document.tpl.php)
恩,是的,就在 $this->html->docdetails 中,是个 string 的变量,是从 documents/document.tpl.php 中取得的
可以 echo $this->html->docdetails; 看看是什么样子的,是输出一个详细信息的列表,这样就好说了
思路: 提取 $this->html->docdetails 中所要的,添加到 $this->splugin(‘pagetitle’, ****** ); 就可以了
可以看一下我的文件的修改部分:
<?php
//$this->splugin( 'pagetitle', _DML_TPL_TITLE_DETAILS ) ;
//添加标题,完成后,形如: 游戏源代码 - 资源下载 - 本站下载(本站下载是其他文件添加上去的)
$title = $this->html->docdetails;
preg_match_all ("/(<([&my;w]+)[^>]*>)(.*)(<&my;/&my;&my;2>)/", $title, $matches);
$this->splugin( 'pagetitle', $matches[3][0]." - "._DML_TPL_TITLE_BROWSE ) ;
?>
OK了,使用的是PHP的正则表达式…这方面我也不太懂…我这个语句是用PHP官方文档的(提取HTML标记内容),可以在 这里 找到
这个语句,肯定还有优化的地方,因为我对正则表达式方面还不要了解,请读者自己研究一下的
恩,这样就可以往title上加入自己想要的内容了,也起到了搜索引擎优化的作用
Trackback from your site.