当前位置: 首页 > 图文教程 > 专题中心 > joomla教程和joomla模板制作教程 > Joomla入门教程 > Joomla教程:禁止未分类文章被站内搜索

Joomla入门教程
Joomla教程:在Joomla 1.5中使用SEF网址
Joomla教程:重置用户密码的3种方法
Joomla教程:使用图片和CSS实现翻转效果菜单
Joomla教程:保持Blog视图中的文章标题链接
Joomla教程:一套模板实现多种布局模式
Joomla教程:去掉分类文章列表中的文章序号
Joomla教程:禁止未分类文章被站内搜索
Joomla教程:网站首页第一次加载时播放一次Flash动画
Joomla中文教程:创建并使用插件对文章内容进行修改
Joomla教程:查看并修改模板的CSS
Joomla教程:为“read more”链接添加对应的文章标题
Joomla教程:为页面和模块添加独立的自定义Class
Joomla教程:在templateDetails.xml中添加语言文件声明
Joomla中文教程:构建多重站点
Joomla教程:在Who is online模块中显示用户名
Joomla教程:本地搭建的Joomla站点发送邮件
在Joomla自定义HTML模块组合使用Google小工具
Joomla教程:mod-rewrite是否真的被开启
Joomla教程:控制Section中的分类列表页面的显示方式
Joomla教程:文章页面中显示指定的模块

Joomla入门教程 中的 Joomla教程:禁止未分类文章被站内搜索


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-12-07   浏览: 83 ::
收藏到网摘: n/a

使用Joomla这样的CMS(内容管理系统)时,一个常见的问题就是如何禁止例如致谢辞页面、注册页面或此类独立的未分类页面被站内搜索

要解决这个问题,我们需要修改这个文件:

joomla根路径/plugins/search/content.php

基于你的需求,我们有两种可选的解决方式。

第一种方式,如果你将所有这些独立的页面都归入“未分类(uncategorised)”这个section,那么可以按照下面的方法去做:

在上面的content.php文件第56行附近找到如下代码:

$sUncategorised = $pluginParams->get( 'search_uncategorised', 1 );

将它注释掉;整个代码段会像下面这样:

// load plugin params info
$plugin =& JPluginHelper::getPlugin('search', 'content');
$pluginParams = new JParameter( $plugin->params );

$sContent = $pluginParams->get( 'search_content', 1 );
// $sUncategorised = $pluginParams->get( 'search_uncategorised', 1 );
$sArchived = $pluginParams->get( 'search_archived', 1 );
$limit = $pluginParams->def( 'search_limit', 50 );

第二种方式,如果你希望做的更具体些,例如使某些特定的文章页面避开站内搜索,那么需要在content.php文件中83行附近加入这行代码:

$wheres2[] = "LOWER(a.metakey) NOT LIKE '{nosearch}'"; 

最终整个代码段会像下面这样:

$wheres = array();
switch ($phrase) {
case 'exact':
$text = $db->getEscaped($text);
$wheres2 = array();
$wheres2[] = "LOWER(a.title) LIKE '%$text%'";
$wheres2[] = "LOWER(a.introtext) LIKE '%$text%'";
$wheres2[] = "LOWER(a.`fulltext`) LIKE '%$text%'";
$wheres2[] = "LOWER(a.metakey) LIKE '%$text%'";
$wheres2[] = "LOWER(a.metadesc) LIKE '%$text%'";
$wheres2[] = "LOWER(a.metakey) NOT LIKE '%{nosearch}%'";
$where = '(' . implode( ') OR (', $wheres2 ) . ')';
break;

现在,你可以将“{nosearch}”添加到某篇文章的参数设置里的“Meta Info - Keywords”中,这样,即使该文章中包含站内搜索的关键字,它也不会出现在搜索结果列表里了。搞定。