当前位置: 首页 > 图文教程 > 网页制作 > CMS技巧 > Joomla教程:禁止未分类文章被站内搜索

CMS技巧
Joomla教程:一套模板实现多种布局模式
Joomla教程:保持Blog视图中的文章标题链接
Joomla教程:使用图片和CSS实现翻转效果菜单
Joomla教程:重置用户密码的3种方法
Joomla教程:在Joomla 1.5中使用SEF网址
drupal网站配置google Sitemap
Drupal在中国悄悄的火起来了
Drupal教程:环境搭建和基本配置
Drupal教程:本地计算机建立多个站点和错误页面设置
drupal教程:添加drupal模块和主题
Drupal教程:创建内容
Drupal教程:自定义区块(Blocks)
Drupal教程:使用drupal菜单
Drupal教程:联系表单(Contact Form)
Drupal中文教程:URL别名
Drupal教程:迁移整个Drupal站点与数据库
Drupal中文教程:设定Cron
Drupal中文教程:分类(Taxonomy)
Drupal中文教程:链接和图片
Drupal简明教程:适用于初学者的Drupal

CMS技巧 中的 Joomla教程:禁止未分类文章被站内搜索


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-03   浏览: 28 ::
收藏到网摘: 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”中,这样,即使该文章中包含站内搜索的关键字,它也不会出现在搜索结果列表里了。搞定。