Contents in blocks and pages with Views
While I was thinking on how to put a list of my contents in this site and how to change their pagination and style between home and the other pages, I was in trouble because I didn't know a handy method for Drupal! Views is the solution! I will show you the operations to create a new view and to distribuite contents in blocks and pages.
In my case I want obtain the following result for two different content types (articolo and articolo del blog):
- block in home page with last 6 published articles (title and teaser trimmed at 120)
- internal page with the last 10 published articles (image with a CSS class, title, teaser trimmed at 400 and link)
These are my choices, but everybody can make their own! Views can offer many possibilities.
You can enable the two existent views as I explained in the previous article, but if you want to create a new view, you have to link your browser here: http://my_site/admin/structure/views, and click on Add new view and then select Create a page and Create a block. In this way:
Well, at this point you can fix the default settings, select the region where you want to put the new block created, it is sufficient to link here: http://my_site/admin/structure/block.
Giving CSS Style
If you have to assign specific graphic effect in some fields, an easy solution is to apply CSS classes. In my case I put a little image in every article and blog page: on the left in the first and on the right in the second list of contents. In this way:
|click on field you want to modify||select item called STYLE SETTINGS||insert the name of CSS class and save all|
Then you have to define the new CSS class in the style sheet of your default theme (in Drupal you find it here: http://my_site/sites/all/themes/mio_tema/css/style.css). I have added the following code for Articoli view:
padding: 15px 15px 20px 0px;
padding: 15px 0px 20px 15px;
I put below two useful pictures to show you my settings, and my export view code here: export_articoli_view.txt (you can import in your Drupal site, it is sufficient to click in the import button in the Views menu page and to Paste view code here, but check the incompatibilities!)
|Display: Page||Display: Block|