Creating the View Itself

The next step is to create a View more convenient for listing that is capable of offering more powerful filtering options. Earlier you modified an existing View to customize the layout of the group home page. You are now going to make a View from scratch. A View is a query generator, and to make it work, you have to provide information about which columns of the database table you wish to include and which search criteria should be invoked to generate the listing. Views also allow you to customize the listings layout and look and feel. And the View not only may be invoked via short snippets of PHP code, but also provides optional block and page renderings. In this case, you are going to use both. Follow these steps:

1. Go to Administer > Site building > Views, and click on the Add tab.

2. Provide a machine-readable name for the view: genre_browser. For now, don't select any special access restrictions.

3. Next, add a short description: Allows the user to browse literary pieces according to genre.

4. Open the Page section, and select the ''Provide Page View'' checkbox. Specify a URL for the page: browse/genre. For the View Type, select Table View. Type Browse literary pieces according to genre in the Title field for the page. Leave the rest of the page items as they are for now at least.

5. Open the Block section. Select the ''Provide Block View'' checkbox. Here, too, select Table View, and enter Browse Literary Pieces as the Title for the block. Put 5 as the maximum number of items to display, and select the More link checkbox.

6. Because you are using the Table View, you need to specify which fields you want displayed as columns in the table. Select Node: Title, and click on the ''Add Field'' button. Type Name in the Label field. Next, add Taxonomy: Terms for Tags, and enter Genre in the Label field. Then, add the fields Node: Author name (Label: Author) and Node: Updated time (Label: Date).

7. Now you just need to specify which content type (node type) you wish displayed; otherwise, all nodes will be displayed. Open the Filters section, and add the Node: Type filter. After clicking on the ''Add field'' link, select Literary Piece in the Value column. In this way, only nodes of type Literary Piece will be included in the listing.

8. Take a look at what you have up till now. Scroll down to the bottom of the page, and click on the Save button. To view genre_browser in page view first, click the URL browse/genre. You should see something similar to Figure 6-21.

9. Two adjustments would be welcome here. Because this is a table view, the number of items per page can be doubled. And the table headings need to be made sortable. Click on the Edit tab, and in the Page section, specify 20 in the ''Nodes per Page'' field. Then, in the Fields section, select Yes in the Sortable column for Name, Author, and Date.

10. After saving your work, you can now click on the Name, Author, and Date columns to sort the listings table in real time.

11. Now check out the Block View. Go to Administer > Site building > Blocks, and you will see that a new block has appeared, bearing the name genre_browser. First, click on the configure link, specify Browse genre as the title of the block itself, and click on the ''Save block'' button. Then enable it for the content region (it's too wide for the left sidebar region, and it is fashionable these days to put navigation blocks at the foot of the page after the page content) with a weight of 1. Click on the ''Save blocks'' button.

12. To finish up the current task, you just need to add the View you have tried out onto the Places navigation menu for Workshop Members. To do so, go to Administer > Site building > Menus, and click on the ''Add item'' link just under the Places heading. Enter Browse by genre in the Title field, enter Browse literary pieces by genre in the Description field, and enter browse/genre (the URL of the page view) in the URL field. Specify a weight of 9, and click ''Submit.''

Drowse literary pieces according to genre | On-lfne literary workshop - Mozllla rlrefox 3 Oeta 5

£tle £dit \£iew l fiitory Qookmarks 3&ols (Jelp

Drowse literary pieces according to genre | On-lfne literary workshop - Mozllla rlrefox 3 Oeta 5

£tle £dit \£iew l fiitory Qookmarks 3&ols (Jelp


Rings Cfvups




^ On-line literary workshop


Genre parade

Browse literary pieces according to genre

i Edit

Cluu'j Exput't

tlegy Free verae Kaibun Haiku Umflrirk Sonnet mors tagt





Loreia ipsum dolor




NuUa fact]»! (a long llaibun»


07/13/20 OS



Quisqtiiv Eipion ante





Sad eonsecteuier nisi eget bgula




My blog

Thn hnnt pLicm



07/1 3/200«

1 3:37

create content

Sonnet one





My unread Recent posts AditimisLur

Sonnet two





Fri-fdnm shtiul night an ftvn



07n a/2oofl


Log out

Freedom ihnut eight nine two

Free mrsfl


07fl 6/2008.


Hiiiffy If] thn Urud 1,1 km



07/5 a/2008


My account

1 2 next ' las


Pout a literary piecu

Post a forum topic

post a bksg entry

Pnvnto rnr«2Sigri5


Now the user can click on the Browse by Genre link in the Places menu, and visualize the listings (20 per page) while the shorter block (first 5 entries) appears on all pages. There is just one thing you need to fix up a little, which is to prevent the block from appearing when the page view does. Go to Administer > Site building > Blocks, click on the configure link corresponding to the genre_browser block, and scroll down to the Page specific visibility settings section. There, select ''Show on every page except the listed pages'' (the default), and enter browse/genre in the Pages text area. While you're at it, add admin and admin/* on the separate, second, and third lines. Click on the ''Save block'' button.

Now, when you select ''Browse by genre'' from the Places navigation menu, the block ceases to appear, while it does appear on every other page, except administration pages.

Commit and deploy.

0 0

Post a comment