Skip to content

Instantly share code, notes, and snippets.

@rubedell
Created October 28, 2013 10:45
Show Gist options
  • Save rubedell/7194800 to your computer and use it in GitHub Desktop.
Save rubedell/7194800 to your computer and use it in GitHub Desktop.
Latest product (withouth views)
<?php
/**
* Implements hook_block_info().
*/
function the_aim_custom_block_info() {
$blocks['latest_product'] = array(
'info' => t('Latest product'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function the_aim_custom_block_view($delta = '') {
$block = array();
switch ($delta) {
//latest product
case 'latest_product':
$block['subject'] = t('Latest product');
$block['content'] = _latest_product();
break;
}
return $block;
}
/* shop overview simple content */
function _latest_product() {
global $language;
$query = db_select('node', 'n');
$node_results = $query->condition('language', $language->language, '=')
->condition('type', 'product_display', '=')
->fields('n', array('nid'))
->orderBy('created', 'desc')
->range(0, 1)
->execute()
->fetchField();
if ($node_results) {
$nodes = node_load($node_results);
$node_view = node_view($nodes, 'home');
return array(
'#theme' => 'latest_product',
'#nodes' => $node_view,
);
;
}
return NULL;
}
function the_aim_custom_theme() {
return array(
'latest_product' => array(
'variables' => array(
'nodes' => NULL
),
'template' => 'latest-product'
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment