Blog of Attomsoft Inc.
Customzie Drupal 6 front page using multiple views
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.
| Print article | This entry was posted by Sean on March 20, 2010 at 1:01 pm, and is filed under Drupal. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
I need some advice for my blog….I like your layout. Can you help me? 8 1 6
about 1 year ago
How often do you write your blogs? I enjoy them a lot 7 6 2
about 1 year ago
One more useful article from your blog
Whenever will it stop….hopefully never
about 1 year ago
To Winifred:
I’m not good at design stuff, this blog just use a contributed theme. I think PSD to Drupal does it well, looks impressive.
TO: Ashley Quam & PSD to Drupal:
Glad to see my posts useful for you guys, I just started blogging recently, and I’ll trying to keep doing this as often as possible.
about 1 year ago
Sean, thanks for this post. This is exactly what I was looking for a month ago. I have come to this page today while searching for something else. Will give this a try.
about 6 months ago
Hi! thans for dis helpful info. In the php snippet (print views_embed_view(“foo-view”,”page”);)can v place block r any other view display in place f page display…?
about 4 months ago
Great report. I really really love your blog posts. I’ll be bookmarking your site so I can refer to it often
about 3 months ago
Good post. I learn one thing more challenging on different blogs every day. It is going to at all times be stimulating to read content material from other writers and follow just a little one thing from their store. I’d favor to use some with the content material on my blog if you don’t mind. I’ll give you a link on your blog. Thanks for sharing.
about 1 day ago
I try this, but nothing display on header or footer -_-’, my step
- enable PHP Code
- create view A
- create view B and add view A as footer, like;
result?. Nothing display -_-’
something mistake???