This document provides an overview of using the Views module in Drupal to create dynamic sections and blocks. It discusses what Views is, common use cases, and administration. It then walks through a case study of creating a latest news section and home page block that dynamically pull from content. It covers adding fields, filters, formats, and advanced settings. It emphasizes best practices like naming, overriding settings, and features integration.
08448380779 Call Girls In Civil Lines Women Seeking Men
Introduction to Drupal 7 News section and home page block with views
1. Introduction to Drupal 7
Session 3.2
News section and home page block
with Views
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 1
2. Agenda
• What is Views
• Common uses
• Administration overviews
• Case study – making dynamic news section
and latest news block for home page
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 2
3. What is Views
• The most popular Drupal module enabling
regular (and not-technical) users to make lists,
tables and other outputs of database queries
in a fun way.
• What we’re going to use Views for:
– Latest news section
– About us section with team members
– Latest news block for home page
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 3
4. Views common use cases
• From http://drupal.org/project/views:
– You like the default front page view, but you find you want to sort it
differently.
– You like the default taxonomy/term view, but you find you want to sort it
differently; for example, alphabetically.
– You use /tracker, but you want to restrict it to posts of a certain type.
– You like the idea of the 'article' module, but it doesn't display articles the way
you like.
– You want a way to display a block with the 5 most recent posts of some
particular type.
– You want to provide 'unread forum posts'.
– You want a monthly archive similar to the typical Movable Type/Wordpress
archives that displays a link to the in the form of "Month, YYYY (X)" where X is
the number of posts that month, and displays them in a block. The links lead
to a simple list of posts for that month.
• Views can do a lot more than that, but those are some of the obvious uses
of Views.
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 4
6. Creating latest news section
• Prerequisites for making it happen:
– Specific content type which will populate the
section, i.e. news content type have to available
– News content type will have at least these 3 fields
• News image – for the news thumbnail
• Original publish date
• Body field or any other text area field
– Views and Chaos tools modules installed
– Already populated content would a plus
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 6
9. Working with the controls
• Adding fields, criteria, etc
– You can use the add button directly
• Rearranging fields
– Use the options arrow on the add button
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 9
11. Format settings explained
• Main format: table (easiest to use for
beginners)
• Title, date and body are grouped with <br/> in
the end
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 11
12. Fields settings explained
• We added the following fields: news image, node
title, original publish date and the body of the
node;
• The order of the fields is important;
• The news image takes the news image preset;
• The node title links to the node itself;
• The publish date is long format;
• The body field is trimmed version to 500 symbols;
• No field labels are needed for this case;
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 12
13. Filter and sort criteria explained
• 2 filter criteria are used for our case:
– Content: Published (Yes) which filters the content
in such a way, that only nodes that are made
available for public will be available
– Content: Type (=News) which filters the content
displayed to be only of type News
• 1 sorting criteria is used for our case:
– Content: Post date (desc) which makes so that the
latest content is placed on top
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 13
14. Page settings explained
• Path: this is the URL which the page receives
• Menu: use if you want to place the page in a menu item, i.e. in the main menu
• Access: rarely used, if you want to directly place some permissions on the section
• Header: used to place text/view before the result view
• Footer: used to place text/view after the result view
• Pager: self-explanatory – used to make pagers for your views section
• More link: used in views blocks mainly
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 14
15. Advanced settings explained
• Contextual filters: used when
dynamic arguments are
passed from the URL for node
id or user id
• Relationships: used when you
need data from a database
table, which is not accessible
in your current state
• No results behavior: place
text/view for cases when your
query does not give results
• Exposed form: used when
your filter criteria are exposed
• Other
– Machine name: important
when you have many views
– Query settings: removing
duplicates happen from here
– Caching: when you want to
make performance tunings
– CSS class: helping themers
– Theme: advanced theming
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 15
16. What would an advanced user do
• Name your view better: for example ‘News
views page’ instead of just ‘Page’
• Give a better machine readable name, for
example ‘news_views_page’ instead of ‘page‘
• You can also tweak the table fields a bit, this is
optional
• To become and advanced user: play with the
views settings as much as you can;
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 16
17. Your dynamic news section is ready
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 17
18. Compile your work so far
• Go to admin/structure/features/create
• Set a name, description and a version
• Select your view and image style news
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 18
19. Adding a second view block
• We want to add another view, which will be a
block, again showing the latest news items
with a title and some text, no image or date
• The block will be used for the front page
• We can reuse some logic from our first view
• We’ll learn how to override views
configurations
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 19
20. Latest news views block
• Go back to your view:
admin/structure/views/view/{your_view}/edit
• Click “Add” and include a new views Block
• The blocks automatically takes most of your views page
configurations
• Override the following:
– The display name of the view
– Remove the fields you don’t need
– Limit the number of items to display to 5
– Change the machine readable name
– Give a block name in the block settings
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 20
21. Important: overriding values
• Click on the a field where the override will be
• Select the override from the drop-down
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 21
22. Deleting fields from views
• You can either click on the field itself and
delete it (after overriding it)
• Or you can use the Arrange option
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 22
23. Tweaking the latest news block view
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 23
24. Your home page news block is ready
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 24
25. Your features is overriden
• We made changes on our News view, and the
Features modules sees the changes
• Therefore, if we work with a repository, the
repository has be updated with our latest
changes version (adding the views block)
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 25
26. Recreate the feature and save it
• Change the version to be up in some way
Drupalist: Kalin Chernev Course by Init Lab (http://initlab.org) 26