Php 将Wordpress首页设置为Algolia搜索

Php 将Wordpress首页设置为Algolia搜索,php,wordpress,templates,search,algolia,Php,Wordpress,Templates,Search,Algolia,我最近安装了一个新的Wordpress,用作调查数据库。该网站的目的是收集调查数据,并允许管理员过滤和搜索提交的调查数据 我已经安装并配置了Algolia搜索WP插件。一切正常。如果导航到“mydomain.com/?s=”我会看到搜索表单并返回结果 我的问题是如何将Algolia搜索页面设置为我的Wordpress索引/首页?或者,如何将此表单导入到可以指定为WP静态首页的页面 进一步信息:我安装了一个子主题,可以创建自定义页面模板/模板部分原因是这里的代码 if ( is_search()

我最近安装了一个新的Wordpress,用作调查数据库。该网站的目的是收集调查数据,并允许管理员过滤和搜索提交的调查数据

我已经安装并配置了Algolia搜索WP插件。一切正常。如果导航到“mydomain.com/?s=”我会看到搜索表单并返回结果

我的问题是如何将Algolia搜索页面设置为我的Wordpress索引/首页?或者,如何将此表单导入到可以指定为WP静态首页的页面


进一步信息:我安装了一个子主题,可以创建自定义页面模板/模板部分

原因是这里的代码

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代码,它工作得很好)


希望有帮助。

原因是这里的代码

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代码,它工作得很好)

希望有帮助