当在PbootCMS英文站上使用搜索功能时,我们可能需要对搜索结果页面的面包屑进行修改以显示中文。以下是修改方法:
打开\apps\home\controller\SearchController.php文件。
在继续之前,请务必备份原始代码,以避免出现问题后无法恢复。
选择以下代码(根据您的PbootCMS版本选择相应的代码),并将其粘贴到SearchController.php文件中:
pb2.1.1版本替换:
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 搜索控制器
*/
namespace app\home\controller;
use core\basic\Controller;
class SearchController extends Controller
{
protected $parser;
protected $htmldir;
public function __construct()
{
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 内容搜索@mk-lang 增加英语
public function index()
{
if (cookie('lg') == 'cn') {
$searchtpl = request('searchtpl');
if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
$searchtpl = 'search.html';
}
$content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = get('keyword') ? get('keyword') . '-' : '';
$content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . '搜索结果-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '搜索', homeurl('search')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 1, '搜索结果', homeurl('search')); // 解析分类标签
$content = $this->parser->parserSearchLabel($content); // 搜索结果标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content; // 搜索页面不缓存
exit();
} else {
$searchtpl = request('searchtpl');
if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
$searchtpl = 'search.html';
}
$content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = get('keyword') ? get('keyword') . '-' : '';
$content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . 'The search results-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, 'Search', homeurl('search')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 1, 'The search results', homeurl('search')); // 解析分类标签
$content = $this->parser->parserSearchLabel($content); // 搜索结果标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content; // 搜索页面不缓存
exit();
}
}
}
pb3.0.3版本替换:
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 搜索控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use core\basic\Url;
class SearchController extends Controller
{
protected $parser;
protected $htmldir;
public function __construct()
{
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 内容搜索
public function index()
{
if (cookie('lg') == 'cn') {
$searchtpl = request('searchtpl');
if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
$searchtpl = 'search.html';
}
$content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = get('keyword') ? get('keyword') . '-' : '';
$content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . '搜索结果-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '搜索', Url::home('search')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 1, '搜索结果', Url::home('search')); // 解析分类标签
$content = $this->parser->parserSearchLabel($content); // 搜索结果标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content; // 搜索页面不缓存
exit();
} else {
$searchtpl = request('searchtpl');
if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
$searchtpl = 'search.html';
}
$content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = get('keyword') ? get('keyword') . '-' : '';
$content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . 'The search results-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, 'Search', Url::home('search')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 1, 'The search results', Url::home('search')); // 解析分类标签
$content = $this->parser->parserSearchLabel($content); // 搜索结果标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content; // 搜索页面不缓存
exit();
}
}
}
将修改后的SearchController.php文件保存,并在PbootCMS中进行搜索操作。您应该会看到面包屑已经显示为中文。
这些简单的步骤可以让您在PbootCMS英文站的搜索结果页面上显示中文面包屑。如果您遇到任何问题,请务必备份原始代码,并随时可以恢复。
本文链接:http://task.lmcjl.com/news/5552.html