18.11.2015 Views

Beginning Drupal 8

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 19 ■ Creating a Blog Site<br />

Before creating the views, it’s a good idea to have content in place that allows us to see our view<br />

in action. Add several dummy blog posts (refer to Chapter 2), selecting various Topics (e.g., Hosting,<br />

Performance, and Theming). After creating blog posts, it’s time to create the main view for the site. Click the<br />

Structure link in the secondary admin menu followed by the Views link on the Structure page. Click the “Add<br />

new view” button and enter a view name of “Blog posts” in the “View name” field. Change the View Settings<br />

by selecting Article in the “of type” select list, followed by clicking the “Save and edit” button. We will want<br />

to create a Block display, so click the Add button and select Block from the list of display types. Make the<br />

following changes to the view:<br />

1. Click the “Display name” link and change the value from “Block” to “Blog<br />

Listing.”<br />

2. Click the Title link and enter “Latest Blog Posts” as the title.<br />

3. Click the Show link and change the value from “Fields” to “Content.” When the<br />

“Row style options” form appears, select the Teaser mode and click the Apply<br />

button.<br />

4. The Sort Criteria section should already be set to sort descending on post date,<br />

which will give us a listing of blog posts with the newest posting displayed at the<br />

top of the list.<br />

5. Click the Save button to save the view.<br />

The second view that we need to create is the list of terms in the Topics vocabulary. We’ll use this list<br />

of terms as a menu to navigate to taxonomy listing pages that show all of the blog postings assigned to<br />

that topic. Click the Structure link in the secondary admin menu and the Views link on the Structure page.<br />

Click the “Add new view” button and enter a view name of “Blog Topics.” In the View Settings fields, select<br />

“Taxonomy terms” from the Show select list, Topics from the “of type” select list, and leave the “sorted by”<br />

field as Unsorted. Click the “Save and edit” button to continue.<br />

We want the view to display as a block, so create a new Block display by clicking the Add button and<br />

selecting Block from the list of display options. Click the “Display name” field and enter “Topics Menu” in<br />

the “Administrative name” field and click the Apply button. Click the Title link and enter “Browse by Topic”<br />

in the Title field, followed by clicking the “Apply (all displays)” button. The view is now ready to save.<br />

Now that we have all the views we need to address the requirements of our site, the next step is to place<br />

the views on the page.<br />

Assigning Blocks<br />

With the views complete, we’re ready to assign to the page the blocks we created. Click the Structure link in<br />

the secondary menu followed by the “Block layout” link. Click the Blog Posts: Blog Listing link in the “Place<br />

blocks” box on the right and select Content as the region to display the list. We want to restrict this view so<br />

that it appears only on the front page of our site (and not on every page that we visit), so select the Pages<br />

tab in the vertical menu at the bottom of the block configuration page and select “Show for the listed pages”<br />

from the “Show block on specific pages” form. In the text box, enter , which is a shortcut that <strong>Drupal</strong><br />

uses to represent the front page of a site, and then click the “Save block” button.<br />

Next, select the Blog Topics: Topics Menu block from the “Place blocks” box and place it in one of the<br />

sidebars provided by your theme. Since commenting is enabled, we’ll want to display a list of the most recent<br />

comments on our site. <strong>Drupal</strong> 8 provides a block that does just that by default. Select the “Recent comments”<br />

block from the “Place blocks” box and place that block in the same sidebar as the Topics menu. Your block<br />

layout should look similar to Figure 19-4. Save your blocks before exiting the “Blocks layout” page.<br />

206

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!