【问题标题】:Setting Wordpress front page as Algolia search将 Wordpress 首页设置为 Algolia 搜索
【发布时间】:2016-10-13 19:22:13
【问题描述】:
我最近安装了一个新的 Wordpress 来充当调查数据库。该网站的目的是收集调查数据并允许管理员过滤和搜索提交的调查数据。
我已经安装并配置了 Algolia 搜索 WP 插件。一切正常。如果我导航到“mydomain.com/?s=”,我会看到搜索表单并且它正在返回结果。
我的问题是如何将 Algolia 搜索页面设置为我的 Wordpress 索引/首页?或者,我如何将此表单导入到我可以指定为我的 WP 静态首页的页面?
更多信息:我安装了一个子主题,可以创建自定义页面模板/模板部分
【问题讨论】:
标签:
php
wordpress
templates
search
algolia
【解决方案1】:
原因是这里的代码...
if ( is_search() && $settings->should_override_search_with_instantsearch() ) {
return $this->load_instantsearch_template();
}
来自这个文件
https://github.com/algolia/algoliasearch-wordpress/blob/1a51d3e2e8be12bfcbccd1ef2a722911a99376e7/includes/class-algolia-template-loader.php
基本上它目前没有被加载到你想要的地方。
将此代码放入您的functions.php 将修复它。
add_action( 'wp_enqueue_scripts', function () {
// Enqueue the instantsearch.js default styles.
wp_enqueue_style( 'algolia-instantsearch' );
// Ensure jQuery is loaded.
wp_enqueue_script( 'jquery' );
// Enqueue the instantsearch.js library.
wp_enqueue_script( 'algolia-instantsearch' );
// WordPress utility useful for using underscore templating.
wp_enqueue_script( 'wp-util' );
// Allow users to easily enqueue custom styles and scripts.
do_action( 'algolia_instantsearch_scripts' );
} );
然后只需添加 Instantsearch.php 代码或将文件包含到您要加载它的索引页面/页面。
(我刚刚用 Instantsearch.php 中的代码替换了 index.php 代码,效果很好)
希望对您有所帮助。