Content overview without views (nodes - terms)
name = the AIM custom
package = the AIM
core = 7.x
<?php
/**
* Implements hook_block_info().
*/
function the_aim_custom_block_info() {
$blocks['shop_overview'] = array(
'info' => t('Shop overview'),
);
$blocks['shop_overview_simple'] = array(
'info' => t('Shop overview simple'),
);
$blocks['job_overview'] = array(
'info' => t('Job overview'),
);
$blocks['category_highlighted'] = array(
'info' => t('Category highlighted'),
);
$blocks['product_highlighted'] = array(
'info' => t('Product highlighted'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function the_aim_custom_block_view($delta = '') {
$block = array();
switch ($delta) {
//shop overview
case 'shop_overview':
$block['subject'] = t('Shop overview');
$block['content'] = _shop_overview();
break;
//shop overview simple (home + contact)
case 'shop_overview_simple':
$block['subject'] = t('Shop overview simple');
$block['content'] = _shop_overview_simple();
break;
//job overview
case 'job_overview':
$block['subject'] = t('Job overview');
$block['content'] = _job_overview();
break;
//category highlights
case 'category_highlighted':
$block['subject'] = t('Category highlighted');
$block['content'] = _category_highlighted();
break;
//product highlighted
case 'product_highlighted':
$block['subject'] = t('Product highlighted');
$block['content'] = _product_highlighted();
break;
}
return $block;
}
/* shop overview content */
function _shop_overview() {
global $language;
$query = db_select('node', 'n');
$node_results = $query->condition('language', $language->language, '=')
->condition('type', 'winkel', '=')
->fields('n', array('nid'))
->execute();
if ($node_results) {
$nids = array();
foreach ($node_results as $node_result) {
$nids[] = $node_result->nid;
}
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$node_view = node_view_multiple($nodes, 'teaser');
return array(
array(
'#theme' => 'overview_shop',
'#nodes' => $node_view['nodes'],
),
);
;
}
}
return NULL;
}
/* shop overview simple content */
function _shop_overview_simple() {
global $language;
$query = db_select('node', 'n');
$node_results = $query->condition('language', $language->language, '=')
->condition('type', 'winkel', '=')
->fields('n', array('nid'))
->execute();
if ($node_results) {
$nids = array();
foreach ($node_results as $node_result) {
$nids[] = $node_result->nid;
}
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$node_view = node_view_multiple($nodes, 'teaser_mini');
return array(
array(
'#theme' => 'overview_shop_simple',
'#nodes' => $node_view['nodes'],
),
);
;
}
}
return NULL;
}
/* job overview content */
function _job_overview() {
global $language;
$query = db_select('node', 'n');
$node_results = $query->condition('language', $language->language, '=')
->condition('type', 'vacature', '=')
->fields('n', array('nid'))
->execute();
if ($node_results) {
$nids = array();
foreach ($node_results as $node_result) {
$nids[] = $node_result->nid;
}
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$node_view = node_view_multiple($nodes, 'teaser');
return array(
array(
'#theme' => 'overview_job',
'#nodes' => $node_view['nodes'],
),
);
;
}
}
return NULL;
}
/* highlighted categories */
function _category_highlighted() {
$query = db_select('taxonomy_term_data', 'td');
$query->leftJoin('field_data_field_in_de_kijker', 'fdk', 'fdk.entity_id = td.tid');
$term_results = $query->fields('td', array('tid'))
->condition('fdk.field_in_de_kijker_value', 1, '=')
->range(0, 2)
->orderRandom()
->execute();
if ($term_results) {
$tids = array();
foreach ($term_results as $term_result) {
$tids[] = $term_result->tid;
}
if (!empty($tids)) {
$terms = taxonomy_term_load_multiple($tids);
$term_view = taxonomy_term_view_multiple($terms, 'home');
return array(
array(
'#theme' => 'overview_cat_highlighted',
'#terms' => $term_view['taxonomy_terms'],
)
);
;
}
}
return NULL;
}
/* highlighted product */
function _product_highlighted() {
global $language;
$query = db_select('node', 'n');
$query->leftJoin('field_data_field_product_in_de_kijker', 'fdk', 'fdk.entity_id = n.nid');
$node_results = $query->fields('n', array('nid'))
->condition('n.language', $language->language, '=')
->condition('n.type', 'product_display', '=')
->condition('fdk.field_product_in_de_kijker_value', 1, '=')
->range(0, 1)
->orderRandom()
->execute();
if ($node_results) {
$nids = array();
foreach ($node_results as $node_result) {
$nids[] = $node_result->nid;
}
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$node_view = node_view_multiple($nodes, 'node_home');
return array(
array(
'#theme' => 'overview_product_highlighted',
'#nodes' => $node_view['nodes'],
)
);
;
}
}
return NULL;
}
function the_aim_custom_theme() {
return array(
'overview_shop_simple' => array(
'variables' => array(
'nodes' => NULL
),
'template' => 'overview-shop-simple'
),
'overview_job' => array(
'variables' => array(
'nodes' => NULL
),
'template' => 'overview-job'
),
'overview_shop' => array(
'variables' => array(
'nodes' => NULL
),
'template' => 'overview-shop'
),
'overview_cat_highlighted' => array(
'variables' => array(
'terms' => NULL
),
'template' => 'overview-cat-highlighted'
),
'overview_product_highlighted' => array(
'variables' => array(
'nodes' => NULL
),
'template' => 'overview-product-highlighted'
)
);
}
<ul class="overview jobs">
<?php foreach (element_children($nodes) as $node): ?>
<li><?php print render($nodes[$node]); ?></li>
<?php endforeach; ?>
</ul>
<ul class="overview jobs">
<?php foreach (element_children($nodes) as $node): ?>
<li><?php print render($nodes[$node]); ?></li>
<?php endforeach; ?>
</ul>
<?php print drupal_render($nodes); ?>
<?php
$max = count(element_children($nodes));
// Set up striping values.
$count = 0;
?>
<ul>
<?php foreach (element_children($nodes) as $node) {
$count++;
$attributes = array();
$attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even');
if ($count % 3 == 0) {
$attributes['class'][] = 'third';
}
?>
<li <?php print drupal_attributes($attributes); ?>><?php print render($nodes[$node]); ?></li>
<?php } ?>
</ul>
<?php
$max = count(element_children($nodes));
// Set up striping values.
$count = 0;
?>
<ul class="shops">
<?php foreach (element_children($nodes) as $node) {
$count++;
$attributes = array();
$attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even');
if ($count % 3 == 0) {
$attributes['class'][] = 'third';
}
?>
<li <?php print drupal_attributes($attributes); ?>><?php print render($nodes[$node]); ?></li>
<?php } ?>
</ul>