1.9 Views: News feed on Drupal
Views module is one of the most popular modules. It allows you to display any data you want News, Articles, Comments, Taxonomy terms in the form of blocks, pages, RSS feeds, CSV files, XML files, and in many other formats. And finally, in Drupal 8 Views in the core! Now it does not need to be installed, Views is in the standard installation.
Let's include on Views and start displaying the data.
Create the content type News.
Now we can create news on the site.
Add a picture to the content type News. To do this, go to the Manage Fields tab. You can use an existing field_image field, which is already used in Articles.
Let's create some news so that there is something to output through Views:
Now we can create our first View. Go to Menu - Structure — Views:
On the Views page, we create a new view:
Now let's fill in the form of creating a new view in order. First, write the name of the view, you can also specify the machine name of the view. We write the name view News, choose what we will display content type News. Also, leave Newest first to display:
Next, select the Create a page, put a check mark. Next, enter the title of the new News page. Next, enter the address at which the news page will be, I wrote news. We will output the Unformatted list (using div tags) in the standard way, we will output it with teasers (brief contents of the nodes, we talked about this in previous lessons).
If there will be a lot of news, more than 10, then we need a page navigator, by default it is worth displaying 10 pieces per page, and we can see the rest of the news by following the navigator links. So leave the settings of the navigator as is Use a pager.
Then we can choose in which menu to display a link to our new news page. I chose main navigation, this is the main menu in the header of the site. And enter the name of the News link. Save.
After that, we will have a page for further view editing. Here we can no longer edit anything and go out to see our news page.
let's make a news block with 3 latest news and a link to the news page. Create another view. We call it the News block, we select the news output.
This time we will not display a page, but a block. We will output unformatted list, fields, according to 3 news. Now save our view. In the block, we will not use pager. Now we can continue to edit our view.
Here we have many settings Title, Format, Fields, filter criteria , Sort criteria , Block settings,Header, Footer, no results behavior, Pager and other advanced settings. In the following lessons, we will analyze each of the items in detail, while let's add another field for the publication date, higher than the headline of the news.
Now you need to find the desired field, namely Authored on. To do this, write Authored on in the field search and check the box to display the field. After that we save changes.
Next, you need to set the date format, I also unchecked the label output:
The publication date is not the date when the content was created, you can display the creation date separately.
The publication date is the time when the content was saved with the checkmark “published”.