Skip to content

Instantly share code, notes, and snippets.

@robballou
Created May 15, 2012 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robballou/2704120 to your computer and use it in GitHub Desktop.
Save robballou/2704120 to your computer and use it in GitHub Desktop.
Custom Module block code
<?php
// hook_block_info
/**
* Our block specific code
*/
function custom_module_block_view($delta = '') {
if ($delta == ''){
// current node
$node = node_load(arg(1));
// get something related from our database
$query = db_select('some_table');
$query
->fields('some_table', array('sid'))
->condition('some_table.nid', $node->nid, '=');
$related_id = $query->execute()->fetchAssoc();
// load our view and pass it
$view = views_get_view('machine_name_for_view');
$view->init();
// you can change this to be the name of the display you want
// to use
$view->set_display('block');
$view->set_arguments(array($related_id['sid']));
return $view->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment