Làm thế nào tạo Search Pages sử dụng Views trong Drupal 7

Làm thế nào tạo Search Pages sử dụng Views trong Drupal 7

>> Hướng dẫn tạo Drupal 7 Content Type Search Block chỉ với 5 Steps

A while ago I wrote two tutorials on using the Search API module. In the first tutorial, we created a custom search page using just Views and a Search API index. In the second, we looked at faceted search using the Facet API module.

Search API can be tough to setup especially for new users to Drupal. For example, you need to understand the difference between a Search API Server and Index, and then you need to spend time configuring everything.

In this tutorial, I'll show you how to create a search page using just Views and Drupal's core Search module.

Getting Started

Before we can begin, download and enable Views. Also make sure you have enabled the core Search module.

If you use Drush, run the following command:

$ drush dl ctools views
$ drush en views views_ui

Search Module

First, make sure you have the Search module enabled. If you installed Drupal using the standard installation profile, then you'll have the module already installed.

Second, make sure you create some content and index that content. Go to Configuration -> "Search settings" and click on "Re-index site".

Fig 1.0

Finally, go to Reports -> "Status report" and click on "run cron manually" in the "Cron maintenance tasks" row.

Làm thế nào tạo Search Pages sử dụng Views trong Drupal 7

When you click on "Re-index site" button, this doesn't index any content it just tells Drupal that the content needs to be re-indexed. The actual index process happens when you run cron.

Create Search View Page

Now that we have the core Search module installed and working, we'll spend some time creating the actual search page using Views.

1. Go to Structure -> Views (admin/structure/views) and click on "Add new view".

2. Fill out the "Add new view" form, using the values defined in Table 1.0 and click on "Continue & edit".

Table 1-0. Create a new view

Option Value
View name Search page
Machine name search_page
Show Content of type All sorted by unsorted
Create a page Checked
Page title Search page
Path search-page
Display format Unformatted list (default)

3. Click on the Add link within the "Filter criteria" and find the "Search: Search Terms" filter and click on "Apply (all displays)".

Fig 1.1

4. On the filter configuration page, check the "Expose this filter to visitors, to allow them to change it" checkbox and "Apply (all displays)".

Fig 1.2

All we have actually done is added the "Search: Search Terms" filter and exposed it so that users can enter in search keywords. The text field will appear above the views page.

At this point, we have a working views page. Save the view, and go to /search-page.

If you enter in some keywords into the "Search Terms" text field, the page should return some results.

Fig 1.4

Display Filter In Block

By default, views places the "Search Terms" text field (exposed filter) above the content area of the page. Views offers you the ability to expose the filter as a block. This is useful if you want to move the exposed filter somewhere else instead of just above the content area.

1. Go to the edit page for the "Search page" view.

2. In the Advanced section, click on the No link next to the "Exposed form in block" label.

Fig 1.5

3. Select Yes from within the pop-up box and click on Apply.

Fig 1.6

4. Once you have configured the view click on Save.

Assign Block To Region

You may notice that the filter is not displaying above the content area, that is because it's now exposed as a block. The last bit of work we need to do is add the exposed filter block to a region within the theme.

1. Go to Structure -> Blocks and assign the "Exposed form: search_page-page" block a specific region.

Fig 1.7

2. Now, if you go to the search page, the filter should be in the assigned block.

Fig 1.8

The last bit of work required is to style the search results. But as you have seen, it's pretty easy to create a custom search page using just Views and the Search module.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn tạo bộ cài đặt MacOS X 10.8 Mountain Lion trên USB

Hướng dẫn tạo bộ cài đặt MacOS X 10.8 Mountain Lion trên USB

Cuối cùng Apple cũng đã chính thức phát hành phiên bản MacOS X 10.8 Mountain Lion và người dùng có thể lên kho ứng dụng Mac AppStore để tải trực tiếp về để upgrade cho máy Mac của mình.

Hướng dẫn viết Conditional CSS for IE10 và IE 11

Hướng dẫn viết Conditional CSS for IE10 và IE 11

While working on recent Drupal projects, I learned that Internet 10 and 11 (IE10-11) no longer support IE conditional comments

The Best Video Player On Android–MoboPlayer

The Best Video Player On Android–MoboPlayer

MoboPlayer is the alternative video player to the default Android player. It is definitely the one app that will replace stock music application that you have been having on your Android phone.

Công ty diệt chuột T&C

 

Diet con trung