💢 原因
微信小程序首页翻页会报数据加载失败,失败率很高,很影响使用体验,而且翻页加载速度很慢,大概每次都要3~6S。所以要找解决方法。还有就是微慕官网有API加速的插件,价格要299元,虽然价格不太贵。但这个应有免费的解决办法。

所以百度了一下,最终找到了解决方法,就是下载安装WP REST CACHE 。设置了下,就解决了问题。
✅ 安装和设置
✅ 安装和启用
在wordpress 后台搜索WP REST CACHE插件,大概在第5、6行,点击安装和启用
✅ 设置插件
插件设置位置在wordprss后台左侧菜单栏的设置👉WP REST Cache
勾上使用Memcache(d)和启用缓存重新生成

然后在主题文件根目录找到functions.php文件夹,加入下面的代码
add_filter( 'wp_rest_cache/allowed_endpoints', function ( $allowed_endpoints ) {
if ( ! isset( $allowed_endpoints[ 'watch-life-net/v1' ] ) ) {
$allowed_endpoints[ 'watch-life-net/v1' ][] = 'posts';
$allowed_endpoints[ 'watch-life-net/v1' ][] = 'rand';
$allowed_endpoints[ 'watch-life-net/v1' ][] = 'options';
$allowed_endpoints[ 'watch-life-net/v1' ][] = 'pageviewsthisyear';
$allowed_endpoints[ 'watch-life-net/v1' ][] = 'category';
}
return $allowed_endpoints;
}, 10, 1 );
代码是根据具体API的URL设置。
比如:微慕小程序首页调用wordprss api 获取文章的URL:https://www.saiita.com.cn/wp-json/watch-life-net/v1/posts?per_page=10&orderby=date&order=desc&page=2
URL里有/wp-json/watch-life-net/v1/posts 路径
就可以设置为$allowed_endpoints[ 'watch-life-net/v1' ][] = 'posts';
其他的URL就以此类推添加。
✅ 查看设置结果
应该基本不会出现数据加载失败的问题了。😏有缓存数据,翻页基本上是秒开。

微信扫描下方的二维码阅读本文
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
暂无评论
要发表评论,您必须先 登录