• No se han encontrado resultados

2. METODOLOGÍA

2.5. Análisis de la estructura planteada

2.5.1. Elementos de la estructura

It might seem that given the challenge of presenting different content types in different ways there are two choices: create a separate view for each or write code in a module or template

file. Depending on the need, the latter might be a reasonable option, but if all that is required is minor differences in content selection, sort order, or the fields to be presented, there is

another alternative available.

We're going to create a view, where most of the settings are made in an umbrella manner, and then create a display containing some minor variances for each content type.

Getting ready

f We'll be using the blog entry and home content types f Enable the blog module if you have not done so

f Details for the home content type are in Appendix B, Bundles f Create some entries for each content type

How to do it...

On the view list page:

1. Navigate to the views list (admin/structure/views) and click the +Add new view

link.

2. Enter Chameleon as View name, check the box for Description, and enter View title and Content type displays in the textbox.

3. The select box settings for Show, of type, and sorted by should be Content, All, and

Title.

4. In the Create a page section, change the Page title from Chameleon to Blog entries, and the Path to content/blog-entries.

5. In the Display format field, change Teasers to Titles (linked)—the adjacent select boxes will disappear.

6. Click the Continue & edit button.

At this point, we have defined most of the information for one display, and now we can

continue on the view edit page:

1. Click the Page link next to Display name and change Name to Blogs, then click the

3. In the Configure field: Content: Post date window, change the label from Post date

to Posted, then click the Apply (all displays) button.

4. Click the Settings link for Show in the Format section, check the box for each field

listed beneath Inline fields, and click the Apply (all displays) button.

5. Click the Add button in the Sort Criteria section, check the box for Content: Post date, and click the Apply (all displays) button.

6. Select Sort descending and click the Apply (all displays) button.

7. Click the downarrow next to the Sort Criteria Add button and select Rearrange, in the resulting window drag the Content: Title field to below Content: Post date and click the Apply (all displays) button.

8. Click the Add button in the Filter criteria section, check the checkbox for Content: Type, and click the Apply (all displays) button.

9. Check the box for Blog entry and click the Apply (all displays) button.

That completes the blog display, but this view will have more than one display. Now we will create the homes display:

1. Click the +Add button next to the Blogs button in the Displays section at the top of the page and select Page.

2. Click the Page link next to Display name and change the name to Homes, then click the Apply button.

3. Click Blog entries next to Title, change All displays to This page (override), enter Homes in the textbox, and click the Apply (this display) button.

4. Click No path is set next to Path in the Page settings box, enter content/homes as the path, and click the Apply button.

5. Click the Content type (= Blog entry) link in the Filters section, change All displays to This page (override), uncheck the checkbox for Blog entry, check the box for

Home, and click the Apply (this display) button.

6. Click the Content: Post date (Posted) link in the Fields section, change the select box to This page (override), and click the Remove button.

7. Click the Add button in the Fields section, check the checkboxes for Content: Home image and Content: House price, and click the Apply (this display) button.

8. Uncheck the Create a label checkbox, select Medium (220x22) in the Image style

select box and Content in the Link image to select box, and click the Apply (this display) button.

9. Uncheck the checkbox for Create a label, change the Thousand marker to Comma, the Scale from 2 to 0, and click the Apply (this display) button.

10. Click the Add button in the Sort criteria section, select This page (override) in the select box, check the box next to Content: House price, and click the Apply (this display) button, and then again in the subsequent window.

11. Click on the sort field links for Content: Post date, ensure that This page (override) is selected, and click the Remove button. Do the same for Content: Title.

12. Click the Save button at the top of the page.

13. Navigate to the /content/blog-entries link to see the following image:

How it works...

We created a content view and two page displays within it, one each for the Blog entry and

Home content types. Each display, so each content type, has its own filters, sort criteria, field

selection, and title.

There's more...

There is more than one way to accomplish the results we see here. We could have created a template for each content type, and one view display that selects records based on an argument. Templates are discussed in the next chapter. The decision should be based on whether there are likely to be changes to the view later on, and who is going to be maintaining it; if a developer or themer, then perhaps a template is the way to go, but if an editor with little or no programming experience, then the method we used would be better.

A variation on this would be to create each display as a block instead of a page, and to assign each to the content area on the front page. If doing so, and if using a pager for each, remember that every pager on a page must have a unique ID number, so be sure to change the pager ID setting for each.

Documento similar