解决Yusi1.0主题使用中存在的问题

欲思主题是一款非常不错的主题,我也是使用的这款主题。但由于PHP版本的更新等,导致Yusi1.0这款主题安装之后不能正常显示和有些工具不能使用等问题,下面我就遇到的问题,提出自己的解决办法,希望能帮助到大家.

一.解决安装好主题后,页面显示不正常的问题(只显示大标题)

这是因为在主题文件header.php中第43行ereg_replace()函数在php7中不再受支持了,已在PHP5中被弃用了,应该换用preg_replace()函数。然后在preg_replace()中加上分界符/,两边要加,即:

preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => 'nav', 'echo' => false)) )

二.解决模板页不能显示的问题

模板页在/yusi1.0/pages/目录下

解决方法:修改该目录下的每一个文件中的ereg_replace()函数,修改方法参照上面。

三.解决文章页头部,评论后不显示评论数,评论数始终为零

解决方法:将single.php中get_comments_number(‘去’,’1′,’%’)改为get_comments_number($post). $post为全局变量。

四.解决固定链接问题(伪静态)

系统:Ubuntu16.04

Apache2: 1.确认Apache2是否开启URL_rewrite;在/etc/apache2/mods-available目录下查看是否有rewrite.load这个文件。

2.在/etc/apache2目录下找到apache2.conf这个文件。打开并找到文件中的下面片段,修改这个文件:

<Directory /var/www/html> //这里指示的是网站的根目录
Options Indexes FollowSymLinks
AllowOverride all // 只需要修改这里,把no改为all
Require all granted
</Directory>

3.在WordPress根目录下找到.htaccess这个文件(这是一个隐藏的文件),打开并在其中添加一句话:

RewriteEngine on

4.重启服务器

nginx: 1.修改/etc/nginx/sites-available/default,在location / block中加上

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename) {
rewrite (.*) /index.php;
}

2.检测语法是否有问题

sudo nginx -t

3.重启nginx

sudo service nginx restart

五.解决搜索不能用的问题

自从使用了http:yourdomain.com/%post_id%.html形式的固定链接以后,search.php 和 moudles/archive_title.php没有做任何改动的情况下,search就能够正常使用。其实只要固定链接的问题解决了,搜索就能够正常使用了。

六.解决PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mb_strimwidth() in /var/www/html/wp-content/themes/yusi1.0/modules/archive_title.php:17

这个错误是在nginx的错误日志中找到的(/var/log/nginx/error.log)
解释:All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring.You probably don’t have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.Apache needs to be restarted afterwards if you are using mod_php
解决办法:

sudo apt-get install php-mbstring
sudo service nginx/apache2 restart

七.解决PHP message: PHP Warning: Use of undefined constant PRC – assumed ‘PRC’ (this will throw an Error in a future version of PHP) in /var/www/html/wp-content/themes/yusi1.0/comments.php on line 17

这个错误也是在nginx错误日志中找到的
解决方法:修改文件./yusi1.0/comments.php 将date_default_timezone_set(PRC)改为date_default_timezone_set(‘PRC’),参数类型应该为:string
参考:

  1. bool date_default_timezone_set ( string $timezone_identifier );

八.解决nginx下首页文章缩略图不能显示的问题

环境:server: ubuntu18,ubuntu16.04 服务器软件:nginx

解决方法:1. 与timthumb.php平级创建cache目录,权限设为:775
2. 安装PHP和 GD image library

sudo apt-get install php7.2 # 安装PHP
sudo apt-get install php7.2-gd # 安装GD库
3.重启nginx
sudo service nginx restart

九.解决文章页最新评论的时间显示问题(比正常时间加8小时)

解决方法:这是一个时区设置问题,修改./comments.php文件,把PRC改为CST。

十.解决(去除)WordPress固定链接中的category字段

解决方法:在主题functions.php函数中添加下列代码:

/**
* 去除固定链接中的/category/路径,添加后在后台保存一次固定链接
* 基于 WP No Category Base 插件
*/

add_action( 'load-themes.php', 'no_category_base_refresh_rules');
add_action('created_category', 'no_category_base_refresh_rules');
add_action('edited_category', 'no_category_base_refresh_rules');
add_action('delete_category', 'no_category_base_refresh_rules');
function no_category_base_refresh_rules() {
global $wp_rewrite;
$wp_rewrite -> flush_rules();
}

// register_deactivation_hook(__FILE__, 'no_category_base_deactivate');
// function no_category_base_deactivate() {
// remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
// // We don't want to insert our custom rules again
// no_category_base_refresh_rules();
// }

// Remove category base
add_action('init', 'no_category_base_permastruct');
function no_category_base_permastruct() {
global $wp_rewrite, $wp_version;
if (version_compare($wp_version, '3.4', '<')) { // For pre-3.4 support $wp_rewrite -> extra_permastructs['category'][0] = '%category%';
} else {
$wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';
}
}
// Add our custom category rewrite rules
add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
function no_category_base_rewrite_rules($category_rewrite) {
//var_dump($category_rewrite); // For Debugging

$category_rewrite = array();
$categories = get_categories(array('hide_empty' => false));
foreach ($categories as $category) {
$category_nicename = $category -> slug;
if ($category -> parent == $category -> cat_ID)// recursive recursion
$category -> parent = 0;
elseif ($category -> parent != 0)
$category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename;
$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';

//var_dump($category_rewrite); // For Debugging
return $category_rewrite;
}
// Add 'category_redirect' query variable
add_filter('query_vars', 'no_category_base_query_vars');
function no_category_base_query_vars($public_query_vars) {
$public_query_vars[] = 'category_redirect';
return $public_query_vars;
}
// Redirect if 'category_redirect' is set
add_filter('request', 'no_category_base_request');
function no_category_base_request($query_vars) {
//print_r($query_vars); // For Debugging
if (isset($query_vars['category_redirect'])) {
$catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category');
status_header(301);
header("Location: $catlink");
exit();
}
return $query_vars;
}

注意:修改完文件之后一定要在后台再重新保存一次固定链接。

十一.解决使用记事本编辑代码后,在vim下打开后出现^M的问题

解决方法:dos2unix filename
dos2unix安装方法:

sudo apt-get install dos2unix
 

本文转载于:志颖博客 » 解决Yusi1.0主题使用中存在的问题

最新更新内容也会在志颖博客上发布!

最后大家在使用过程中存在什么问题,欢迎到主站志颖博客留言!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值