導讀:建站文章建站文章你使用過百度吧~~你知道當你輸入關鍵詞的一部分時,關鍵詞的剩下的部分會提示出來的,如此神奇的效果對于wordpess是前所未有的,大致的意思是,你輸入關鍵字,會網站怎么搭建建站技術模板。

你使用過百度吧~~你知道當你輸入關鍵詞的一部分時,關鍵詞的剩下的部分會提示出來的,如此神奇的效果對于wordpess是前所未有的,大致的意思是,你輸入關鍵字,會自動提示搜索結果,當然是不影響enter進入搜索頁面的,看上去高端大氣上檔次~你可以去感受下,實用性就不做評價了,重要的是可以裝逼~廢話不多數,let’s do it.首先要改裝你的search.php,讓這貨可以返回json數據,把 get_header() 替換成下面的代碼。
<code><?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
$array_posts = array ();
if (have_posts()) :
while (have_posts()) : the_post();
array_push($array_posts, array("title"=>get_the_title(),"url"=>get_permalink()));
endwhile;
endif;
echo json_encode($array_posts);
} else {
get_header(); ?></code>
把 get_footer() 替換成下面的代碼
<code><?php get_footer();}?></code>
這樣就能返回json數據了,然后還得裝修下你的搜索樣式,主要是為提示結果做定位的。
<code><div id="search-container" class="ajax_search">
<form method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<div class="filter_container"><input type="text" value="" autocomplete="off" placeholder="輸入內容并回車" name="s" id="search-input"/><ul id="search_filtered" class="search_filtered"></ul> </div>
關鍵詞標簽: 建站 div 提示
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-07-23 ,文章wordpress ajax實現搜索提示,建站文章主要講述提示,div,建站網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_34887.html