成都创新互联网站制作重庆分公司

wordpress怎么搜 wordpress怎么搜索作者

wordpress 怎么搜索代码

亲,你好,很高兴为你回答。

成都创新互联公司自2013年起,先为临沂等服务建站,临沂等地企业,进行企业商务咨询服务。为临沂企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

首先你要准备2个文件

1个是在wordpress主题下的search.php文件

1个是检索页面需要放入html代码。

form action="/" method="get" input name="s" type="text" placeholder="网站检索" id="s" value="? the_search_query(); ?" / input name="sa" value="检索" type="image" src="?php bloginfo('template_url'); ?/images/search_icon.gif" align="top" class="btn" / /form

上面这些是放在页面的form表单

========================================================================

下面这些是放在search.php里的代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

?php

/**

* The template for displaying all pages.

*

* This is the template that displays all pages by default.

* Please note that this is the WordPress construct of pages

* and that other 'pages' on your WordPress site will use a

* different template.

*

* @package Hotlink

* @subpackage Hotlink Theme

*/

// 検索结果用

$search_query = new WP_Query("s=$s showposts=-1");

get_header(); ?

section class="main clearfix"

?php if (have_posts()) : while (have_posts()) : the_post(); ?

div id="post-?php the_ID(); ?" class="search_post"

div class="search_title"

a href="?php the_permalink(); ?" title="?php the_title_attribute(); ?" rel="bookmark"

?php the_title(); ?

span class="search_text"?php the_excerpt(); ?/span

/a/div

?php the_date() ? ?php the_time() ?

/div

?php endwhile; else: ?

p class="search_text"

?php _e('您要搜索的内容不存在'); ?

/p

?php endif; ?

div class="nav-previous"

?php previous_posts_link(__('« Older Entries', 'kubrick')); ?

/div

div class="nav-next"

?php next_posts_link(__('Newer Entries »', 'kubrick')); ?

/div

/section

?php get_footer(); ?

如果可以使用,记得采纳呦。。有问题继续追问我。

如何搜索 wordpress文章

WordPress 默认的搜索功能还真挺弱的,搜索出来的结果很不符合人意,如果你想让它检索出来的结果更加相关,可以限定只搜索文章的标题,将下面的代码添加到主题的 functions.php 文件即可:

/**

* 让 WordPress 只搜索文章的标题

*

*/

function __search_by_title_only( $search, $wp_query )

{

global $wpdb;

if ( empty( $search ) )

return $search; // skip processing - no search term in query

$q = $wp_query-query_vars;

$n = ! empty( $q['exact'] ) ? '' : '%';

$search =

$searchand = '';

foreach ( (array) $q['search_terms'] as $term ) {

$term = esc_sql( like_escape( $term ) );

$search .= "{$searchand}($wpdb-posts.post_title LIKE '{$n}{$term}{$n}')";

$searchand = ' AND ';

}

if ( ! empty( $search ) ) {

$search = " AND ({$search}) ";

if ( ! is_user_logged_in() )

$search .= " AND ($wpdb-posts.post_password = '') ";

}

return $search;

}

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

wordpress怎么设置搜索功能

wordpress系统本身是对搜索引擎友好的,如果网站的内容比较私密不希望蜘蛛爬取,可以能过以下方法实现:

1、进入wordpress "设置" - "阅读" - 然后勾选“建议搜索引擎不索引本站点”,再点击 “保存更改”。这样搜索引擎就不会收录和索引网站了。

2、还可以通过配置“robots.txt”来告诉搜索引擎,不要收录/索引网站的内容;

步骤:

1),新建一个文本文档,重命名为“robots.txt”;

2),在文本文件贴入以下内容并保存:

User-agent: * Disallow: / 3),将设置好的“robots.txt”上传至网站的根目录。


当前题目:wordpress怎么搜 wordpress怎么搜索作者
当前URL:http://cxhlcq.com/article/ddoochp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部