Drupal ist ein Content-Management-System (CMS) und -Framework. Seine Hauptanwendung findet Drupal bei der Organisation von Websites, zurzeit (November 2014) bei 1,9% aller Websites mit einem Marktanteil von 5,1% bei CMS laut W3Techs. Ursprünglich wurde es vom belgischen Informatiker Dries Buytaert konzipiert. Drupal ist eine freie Software und steht unter der GNU General Public License. Es ist in PHP geschrieben und verwendet MySQL/MariaDB (empfohlen), PostgreSQL (unterstützt), SQLite (ab 7.x), Oracle (per Erweiterung) oder MSSQLServer (per Erweiterung) als Datenbanksystem.
Block im Node einbinden (D7)
<?php
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
?>
'module_name' = The machine name of the module (i.e. the module's folder name). This is true for core modules too, so for instance 'search', 'user' and 'comment' would all work here. 'block_delta' = The machine name of the block. You can determine what this is by visiting the block administration page and editing the block. The URL for editing a webform block, for instance, would be something like: Drupal 7: admin/structure/block/manage/webform/*client-block-11*/configure In this example, 'webform' is the module's name, 'client-block-11' is the block's delta. Custom blocks will have module name of 'block' and a number for a delta, which you can also find by editing the block. More information: http://drupal.org/node/26502
Re-add taxonomy_term_count_nodes()
Leider ist wurde die Funktion zum zählen der Nodes eines Taxonomy terms (taxonomy_term_count_nodes()
) mit Drupal 7 entfernt. Aber Drupal wäre nicht Drupal wenn es keine Lösung[note]https://www.drupal.org/node/602240#comment-6053616[/note] dafür gäbe.
* @param tid
* Term ID
* @param child_count
* TRUE - Also count all nodes in child terms (if they exists) - Default
* FALSE - Count only nodes related to Term ID
*/
function term_nc($tid, $child_count = TRUE) {
$tids = array($tid);
if ($child_count){
$tids = array_merge($tids, term_get_children_ids($tid));
}
global $language;
$langs = array($language->language);
$langs[] = 'und';
$query = db_select('taxonomy_index', 't');
$query->condition('tid', $tids, 'IN');
$query->join('node', 'n', 't.nid = n.nid');
$query->condition('n.status', 1, '=');
$query->condition('n.language', $langs, 'IN');
$count = $query->countQuery()->execute()->fetchField();
return $count;
}
/**
* Retrieve ids of term children .
*
* @param $tid
* The term's ID.
* @param $tids
* An array where ids of term children will be added
*/
function term_get_children_ids($tid) {
$children = taxonomy_get_children($tid);
$tids=array();
if (!empty($children))
{
foreach($children as $child)
{
$tids[] = $child->tid;
$tids = array_merge($tids, term_get_children_ids($child->tid));
}
}
return $tids;
}
oder etwas eleganter
function taxonomy_term_count_nodes($tid, $type = 0) {
static $count;
if (isset($count[$type][$tid])) {
return $count[$type][$tid];
}
$query = db_select('taxonomy_index', 't');
$query->condition('tid', $tid, '=');
$query->addExpression('COUNT(*)', 'count_nodes');
// Restrict query by Content Type
if (!empty($type)) {
$query->join('node', 'n', 't.nid = n.nid');
$query->condition('type', $type, '=');
}
$count[$type][$tid] = $query->execute()->fetchField();
return $count[$type][$tid];
}
Filtertipps deaktivieren (D7)
Via template.php
kann man diese unsäglich viel Platz wegnehmenden Filter Tipps/Guidelines deaktivieren.
function MYTHEME_filter_guidelines($variables) {
return '';
}
Disqus Node Link
<div class="float_left small"style="margin-top: 1.8em; margin-left:-0.2em;"> <?php print '<a href="node/'. $node->nid .'#disqus_thread" data-disqus-identifier="node/'. $node->nid .'">Kommentare</a>';?></div>
$path variable im Theme
/*
* Adding full path variable to Drupal 7 Themes.
* Use: print $design_path;
*/
function MYTHEME_preprocess_html(&$variables) {
$variables['design_path'] = base_path() . path_to_theme() .’/’;
}