将 Wordpress 主页设置为 Algolia 搜索
Setting Wordpress front page as Algolia search
我最近安装了一个新的 Wordpress 作为调查数据库。该站点的目的是收集调查数据并允许管理员过滤和搜索提交的调查数据。
我已经安装并配置了 Algolia 搜索 WP 插件。一切正常。如果我导航到 'mydomain.com/?s=',我会看到搜索表单并返回结果。
My question is how can I set the Algolia search page as my Wordpress index/front page? Or, how can I import this form to a page that I can designate as my WP static front page?
更多信息:我安装了子主题并可以创建自定义页面templates/template-parts
原因是这段代码在这里...
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 代码或将文件包含到要加载它的索引 page/page 中。
(我刚刚用 instantsearch.php 中的代码替换了 index.php 代码,它工作得很好)
希望对您有所帮助。
我最近安装了一个新的 Wordpress 作为调查数据库。该站点的目的是收集调查数据并允许管理员过滤和搜索提交的调查数据。
我已经安装并配置了 Algolia 搜索 WP 插件。一切正常。如果我导航到 'mydomain.com/?s=',我会看到搜索表单并返回结果。
My question is how can I set the Algolia search page as my Wordpress index/front page? Or, how can I import this form to a page that I can designate as my WP static front page?
更多信息:我安装了子主题并可以创建自定义页面templates/template-parts
原因是这段代码在这里...
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 代码或将文件包含到要加载它的索引 page/page 中。
(我刚刚用 instantsearch.php 中的代码替换了 index.php 代码,它工作得很好)
希望对您有所帮助。