Hi there,
I first tried posting this question about invoking a view using PHP to the forums, but had no luck. I hope you'll be able to help. I love the insert view module, and I'm looking forward to seeing it for D6!
Here's the question, as posted to the forums:
In Drupal 5, I used to use the great module Insert View quite a bit to put the contents of a view into the a node. Insert view is almost ready for Drupal 6, but I'm curious:
How would I do this on my own using PHP?
The Insert View docs mention that you can "invoke a view using PHP" but I'm having trouble finding directions on how to do this.
Say, for example, I've got a View that creates the following query:
SELECT node.title AS node_title,
COUNT(node.nid) AS num_records
FROM node node
WHERE node.type in ('news')
GROUP BY node_title
ORDER BY node_title DESC
How would I wrap that up so that I could place a snippet of PHP within a node to invoke the view? (Note - I've got the PHP module activated and appropriate permissions set).
Thanks!
Doug
Comments
Comment #1
mlsamuelson commentedIn Views 2 / Drupal 6 you can insert a view using Views' views_embed_view() function.
If you check the function definition for views_embed_view() in views.module you'll find this very helpful bit of documentation:
In Insert View we use a slightly different approach: get the view's object using the name of the view w/ views_get_view(), and then render the view's object with a $view->preview(). The benefit of this is that it doesn't bring along unnecessary block display related stuff.
mlsamuelson
Comment #2
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.