snippets

FlexSlider in Drupal using Entity Field Query (EFQ)

Today I learnt how to stop using views for every little listing of entities while staying away from hacking SQL queries manually.

I'm a bit ashamed I haven't had a look at the infamous EntityFieldQuery class this far.

Here's my example that builds and inserts a FlexSlider slideshow within my page.tpl.php only for the front page.

In my case FlexSlider is installed and registered as a Library using Libraries and the FlexSlider module (making it possible to load the necessary assets using drupal_add_library

Drupal 7: Hide a Block for a certain content type

Per default block configuration you can only decide to show a block for certain content types, the other way around requires a little bit of PHP. The following snippet hides a block on nodes of type article and blog:

<?php
  // Only show if $match is true
  $match = true;

  // Which node types to NOT show block
  $types = array('article', 'blog');

  // Match current node type with array of types
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load($nid);
    $type = $node->type;
    if(in_array($type, $types)) {$match=false;}
  }
  return $match;
?>