网络建站知识发布于分享网站

当前位置:首页>>新闻中心>>CMS教程>>pbootcms教程

如何修改PbootCMS英文站搜索结果页面中面包屑显示为中文的方法

时间:2025-04-01 03:17:27    来源:    人气:0

修改PbootCMS英文站搜索效果页面包屑显示中文的方法

在使用PbootCMS构建多语言网站时,可能会遇到英文站搜索结果页面的面包屑导航仍然显示中文的问题。为了解决这一问题,我们需要对相关文件进行代码替换操作。以下是具体步骤和代码示例:

首先,打开文件路径:
\\apps\\home\\controller\\SearchController.php
将其中的代码根据您的版本号(2.1.1或3.0.3)分别替换为以下内容。


// PB 2.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();
        }
    }
}
    


// PB 3.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();
        }
    }
}
    

完成上述代码替换后,保存并刷新您的站点。
最终效果如下图所示:

图片[2]-PbootCMS英文站搜索效果页面包屑显示中文的修改方法-论坛搭建_网站论坛制作_论坛开发建设_800元全包

通过以上步骤,您可以成功实现PbootCMS英文站点搜索页面面包屑导航的中英切换功能。

相关文章

  • Pbootcms修改留言“提交成功”提示语

    Pbootcms修改留言“提交成功”提示语

    如果您正在使用 PbootCMS 构建网站,并希望自定义留言功能的提示语,那么本文将为您提供详细的指导。通过修改相关文件,您可以轻松更改“提交成功”的提示语,以满足您的个性化需求。以下是具体的操作步骤: 首先,您需要找到并打开以下文件路径: /apps/home/controller/Messag...
    2025-04-01
  • PBootCMS上传缩略图尺寸限制修改方法

    PBootCMS上传缩略图尺寸限制修改方法

    在使用PbootCMS为客户搭建网站的过程中,可能会遇到上传缩略图时尺寸被限制的问题。例如,上传一张1920px宽的图片后,发现实际显示的尺寸仅为1000px,而在后台找不到相关设置选项。实际上,这种缩略图尺寸的限制是需要通过修改系统文件来解决的。 PbootCMS程序默认将缩略图的最大尺寸限...
    2025-04-01
  • PBootCMS模板中如何调用网站全部文章

    PBootCMS模板中如何调用网站全部文章

    在使用PBootCMS构建网站时,许多人可能会遇到如何在模板文件中调用全站所有文章的需求。本文将详细介绍如何通过PBootCMS的标签语法实现这一功能,并提供一些实用的技巧。 要调用网站所有的文章,可以使用PBootCMS提供的列表标签 `{pboot:list}`。以下是具体的操作方法: ...
    2025-04-01
  • PBootCMS编辑器过滤DIV代码的解决方法

    PBootCMS编辑器过滤DIV代码的解决方法

    在使用 PbootCMS 构建网站的过程中,您可能会遇到需要在专题内容中插入包含 HTML 代码的情况。然而,当您尝试这样做时,会发现编辑器自动去除了部分标签元素,并且将所有的 div 标签转换为了 p 标签。那么,我们该如何解决这个问题呢? AB模板网的专家表示,这是由于编辑器自身的机制导致...
    2025-04-01

公众号