Blog of Attomsoft Inc.
Posts tagged Views
Great Drupal module “View Attach” for node relationship
Mar 23rd
Views’ “Relations” mechanism is great for node relationship displays, but the “View Attach” makes it more powerful and easy to use.
The basic idea behind the “View Attach” module is providing a way to display nodes which have refereed the current node, it’s perfect for “friends list”, “also bought”, “companies support this”, etc.
It’s really a great module, although you can’t figure out what to do with it at first glance, but if you know it well, unstoppable power comes to you.
Customzie Drupal 6 front page using multiple views
Mar 20th
Drupal Views module may be the most powerful, useful and handy tool for Drupal webmasters, The Views2 module gets much better and powerful.
We received a request from one of our client that they wanted to list all of their newest ratings tables on the front page. We had done such job by customize a view filled with CCK fields and set the view as the default front page.
This time, I want a different approach to this request,a more extensible, more professional way.
Here is the solution I used.
- Create all views to be displayed on the front page, like foo-view, bar-view, etc. And theming them as usual.
- Create a new view which you will set it as the new front page, or just enable the front page emulation view from the Views 2 distribution. Name it frontpage-view or something meaningful.
- On the frontpage-view edit page, configure all parameters for normal front page display, such as filters for display news, blog posts, etc.
- Here comes the magics: Lets suppose we want to display the previous created foo-view, bar-view on the to of our new front page. Choose the “Page” display of the frontpage-view, click “Header” link in the “Basic settings” section, choose PHP code as the input format.(If it was not available, enable the module first.)
- Code in the “Header” textarea:
<?php
print views_embed_view(“foo-view”,”page”);
print views_embed_view(“bar-view”,”page”);
?> - Update the settings.
- Set the “Path” of the “Page settings” section as “frontpage” or something meaningful, update the settings and save the view.
- On the “admin->settings->site information” page, set the “Default front page” path as “frontpage” just same as #7 settings. And save.
OK, now just reload your home page, everything should be displayed as we supposed.
Note: The “views_embed_view” function is introduced to Views 2, not available in Views 1.
Tips:
- If you want the foo-view, bar-view display on the bottom of the frontpage-view, move the #5 code to “Footer” settings;
- If the frontpage-view got nothing to display, the whole page will be blank, to make it work in a blank “container”, make the “Display even if view has no result” option checked, the option is just above the textarea which you enter the #5 code.
- You can pass parameters to the “views_embed_view” function of #5 code, details goes here.
Make no sense? Ok, maybe I should post some basic tutorials above Views 2 some day to make this post easy to understand.