• No results found

specific user

In document Drupal 7 Views Cookbook (Page 33-37)

The glossary view presents a list of all content organized by the first letter of the title. This is

a convenient view for site visitors that know the name of the content they are seeking, or who simply want to browse. We're going to give the user the ability to browse the content created

Getting ready

1. Ensure that your site has content posted by more than one author (for testing purposes).

2. Navigate to the Views page (admin/structure/views) and click on the Enable

link for the Glossary view.

3. Click on the down arrow beside the Edit link for the same view, and from the drop- down menu, click on the Clone link.

4. Enter Author glossary for the view name and click on the Continue button.

How to do it...

The glossary view, and now the clone that we created, has two displays: the page display that lists content, and an attachment display that lists each letter of the alphabet for which there is content, along with the number of applicable pieces. We will make some changes to the existing displays and create an additional one that will provide the author list.

1. Click on the +Add button in the Displays section at the top of the page and select

Attachment from the list.

2. Click on the Attachment link next to display name and change the name to New attachment, so we can tell one display button from the other, and click on the Apply

button.

3. Click on the Add button in the Sort criteria section, select This attachment (override) from the For select box, check the box for User: Name and click on the

Apply (this display) button, and in the configuration window that opens, click on the Apply (this display) button.

4. In the Attachment Settings section, click on Before next to Attachment position, select the radio button for After, and click on the Apply button.

5. Click on the Not defined link next to Attach to in the Attachment Settings section, check the box for Page, and click on the Apply button.

6. In the Fields section, click the Content: Title link, select This attachment (override)

from the For select box, and click on the Remove button. 7. Do the same and remove the Content: Updated date field.

8. Click on the Advanced link to open that section, then click on the Settings link next to Query settings in the Other section, select This attachment (override) from the

For select box, check the box for Distinct, check the box below it for Pure Distinct, and click on the Apply (this display) button.

That is the work needed for the attachment itself. Now, we need to make a few minor changes to the settings from the page display.

10. Click on the Advanced link to expand that section.

11. In the Other section, click on the Yes link for Use AJAX, select No, and click on the

Apply button.

12. Click on the Content: Title link in the Contextual filters section, select This page (override) from the For select box, and in the section titled When the filter value is

Not in the URL ensure provide default value of type fixed value of a is the setting. 13. In the section When the filter value is in the URL, check the box for Override title,

enter Content beginning with %1, and click on the Apply (this display) button. 14. Click on the Add button in the Contextual filters section, select This page (override)

from the For select box, scroll down and check the box for User: Name, and click on the Apply (this display) button.

15. In the subsequent configuration window, in the When the filter value Is in the URL section, check the box for Override title, enter Content for author %2, and click on the Apply (this display) button.

16. Click on the (author) User: Name link in the Fields section, ensure that the checkbox for Link this field to its user is not checked, scroll down and click the Rewrite Results link, check the box for Output this field as a link, enter author-glossary/ all/[name] as the link path, then click on the Apply (all displays) button.

17. Click on the /glossary link next to path in the Page settings section, change the path to author-glossary (no leading slash) and click on the Apply button.

18. Click on the Normal: Glossary link next to Menu in the same section, change the title from Glossary to Author glossary, and click on the Apply button.

19. Click on the Save button.

20. Navigate to the home page. First invoke the view simply by click on the Author Glossary link in the navigation menu, and then making a selection of one of the letters shown. Notice the new attachment below the list of content. Yours will vary from the following image, based on the authors on your site:

21. Then, click on the name of an author in the author attachment.

How it works...

We added a new attachment display to the existing view, giving it three displays. The first is

the page display, which is the section of the view containing the information about content.

The second is the original attachment, which appears first on the page, and is formatted as a summary of the available titles using the first letter of the title, giving a total for each letter.

The new attachment appears last, and contains the names of each author who has content on the site.

We specified that the new attachment would inherit two arguments from the page display (which receives the arguments), those being the additional portions of the URL. The first argument is the title of a piece of content, or "all" to specify that all should be used. The

second argument is the name of an author, or is omitted entirely for all authors to be

selected. We turned off AJAX processing of the links, because when using AJAX the

page is not reloaded, so the new arguments are not picked up for the title.

The link produced for each author name links back to the same view, providing "all" as the

title being searched (so, all titles) and the author's name. Thus, the page URL when selected from the menu item appears as author_glossary with no arguments, in which case all records are retrieved; when an author link is clicked, a is inserted as a default; and author_glossary/all/author_name, where all titles belonging to that author are retrieved.

There's more...

Attachment displays are a boon to the value of your views and your site. You can find several

Creating an attached menu for the taxonomy

In document Drupal 7 Views Cookbook (Page 33-37)