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

CMS技巧
Phpcms2008网站内容管理系统免费开源
UCenter 1.5.0安装介绍
Discuz! 7.0论坛模板制作更加简单化
dede文章列表页调用TAG标签
删除Dedecms中遗留的多余图片
JTBC(.NET)将OS管理操作模式融入CMS
UCenter Home站点添加统计代码
论坛程序Discuz!7.0.0安装教程
利用好Discuz!论坛的分类信息功能
用好SNS建站软件UCenter Home词语屏蔽
2009预测中国网站建站10大欢迎CMS
UCenter Home从QQ地址薄导入好友邮箱功能
高流量WordPress博客优化的经验和看法
22个高质量的免费wordpress博客模板
Wordpress教程:wp_list_pages()函数
康盛创想SupeSite 7.0全面开源发布
Wordpress博客首页中的每篇日志添加图片
介绍worpress博客header.php
WordPress主题的index.php代码
wordpress博客wp_list_categories标签

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


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