pbootcms英文站搜索结果页面包屑和标题翻译

作者:PB模板网 时间:2020-12-20 22:42:16 浏览:2609 点赞:331
2609

在使用pbootcms搭建英文站时会发现搜索结果页的面包屑为中文,标题为英文,该如何处理?可二开增加英文站对应文字来解决。

image.png

修改内容

打开\apps\home\controller\SearchController.php,把里面的代码全部替换成以下(分为2x和3x版本,对应版本替换):

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();
        }
    }
}

替换效果

image.png


文章链接:https://www.pbhtml.com/232.html
文章标题:pbootcms英文站搜索结果页面包屑和标题翻译
文章版权:PB模板网 (www.pbhtml.com) 所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!
本文最后更新发布于2022-11-28 18:02:20,某些文章具有时效性,若有错误或已失效,请在下方留言或联系客服:pbhtml@qq.com

相关阅读

用户评论(测试中无法使用)

通知公告
PbootCMS安全提示
pbootcms网站上线后需要做防护
权限设置|数据库路径|主机防护...
我要查看