·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设问答 >> Joomla技巧 - 如何禁止未分类文章被站内搜索

Joomla技巧 - 如何禁止未分类文章被站内搜索

作者:佚名      网站建设问答编辑:admin      更新时间:2022-07-23

使用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”中,这样,即使该文章中包含站内搜索的关键字,它也不会出现在搜索结果列表里了。搞定。

译者:Viiiix