Taxonomy based block visibility snippet

August 3, 2007

//Displays block on all nodes off specific taxonomy term or it’s child terms. Mighty useful in lots of cases.

<?php
$root_term = taxonomy_get_term(54);
$tree = taxonomy_get_tree($root_term->vid, $root_term->tid);
$terms = array_map(’_taxonomy_get_tid_from_term’, $tree);
$terms[] = $root_term->tid;

// $terms now contains all descendant terms.

//print_r( $terms );

if ((arg(0) == ‘node’) && is_numeric(arg(1)))
{
$node = node_load(arg(1));
if (array_intersect(array_keys($node->taxonomy), $terms))
return TRUE;
}

if ( (arg(0) == ‘taxonomy’) && (arg(1) == ‘term’) && in_array(arg(2), $terms) )
{
return TRUE;
}

return FALSE;
?>


Arbitrary Snippets

August 3, 2007

<?php if (isset($primary_links)) { ?><div id=”primary”><?php print theme(’primary’, $primary_links) ?></div><?php } ?>

Will render an active class when the node is being viewed…So that you can add a a.active { class to add your css attribtes to.. Could be a bg color, onHover event or whatever else..


Teasers broken with CCK

August 3, 2007

Uh…after much efforts trying to sort it out and an innate lethargia, paranoia to hack core.. (especially that dru 5.2 is out just now ..and that I’ll wait for a few before I upgrade).. Here’s the despo fix for Missing Read-Mores ($node->readmore bool thats almost always false).

<div class=”field field-type-text field-field-location”>
<h3 class=”field-label”>Location</h3>
<div class=”field-items”>
<?php foreach ((array)$field_location as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
</div>
</div>

<div class=”field field-type-text field-field-description”>
<h3 class=”field-label”>Overview</h3>
<div class=”field-items”>
<?php foreach ((array)$field_description as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
</div>
</div>

<div class=”field field-type-text field-field-schedule–itinerary”>
<h3 class=”field-label”>Itinerary  </h3>
<div class=”field-items”>
<?php foreach ((array)$field_schedule__itinerary as $item) { ?>
<div class=”field-item”><?php print $item['view'] ?></div>
<?php } ?>
</div>
</div>
<div align=”left”><span class=”readmore”><?php print l(’« More »’, ‘node/’.$nid, array(’title’ => ‘Read more on this article’)); ?></span></div>

The lastline was manually added to the template :))..That will not do any strlen()s to validate teaser length to set the readmore bool…but will just display that More link in the teaser view anyway…Works for now, I think this will be fixed in dru6 if I’m not wrong

BTW… The teasers themselves break down When used with Custom Links..More CCK-Readmore-Teaser issues!


IE 7 is a blight upon the society

August 3, 2007

Uh yeah…so my friend and I half-rewrote our 3 column Zen theme to make it look good..and cool IE7 breaks it down like a biatch. Ie 6 is not a lot better..but atleast not as worse. Firefox, Safari3, Knoqueror, Epiphany et al worked with it as smooth as clockwork..Validates..except for the Star Selectors (Which I later realised dint work with IE7 anymore)

Much to my selective Php n00bishness.. I thought the get_browser() would be blocked by most hosts as it would have to ‘phone out’ to the client browser… Contradictorily, It wasnt.. Much to my lethargy to write elonquent code lines with hundreds of $_SERVER[HTTP_USER_AGENT] thingys, I ran into the Browscap module whilst randomly browsing in the contrib.module section on the cvs…Just what I needed!

So now that the Browscap module populates a full list of browsers that exist, all I had to do was spend a couple of hours on writing something to filter site compatibility by browser…and obviously IE 7 was getting nothing but the phptemplate_maintenence_page!

Earlier, I was driven to the verge of baldness, suicide, depression after continual pissing around with conditional comment lines to get IE7 to use a stylesheet it likes…But sadly enough, IE remained obstinate.

All that done, Ie7 blocked and IE6 warded off with a warning, a google ad script for the IE7 maitenence page… It was a happy ending.

function phptemplate_maintenance_page($content, $messages = TRUE, $partial = FALSE) {
drupal_set_header(’Content-Type: text/html; charset=utf-8′);
drupal_set_html_head(’@import “‘. base_path() . drupal_get_path(’module’, ’system’) .’/defaults.css”;’);
drupal_set_html_head(’@import “‘. base_path() . drupal_get_path(’module’, ’system’) .’/system.css”;’);
drupal_set_html_head(’@import “‘. base_path() . path_to_theme() .’/maintenance.css”;’);
drupal_set_html_head(’

‘);
$output = “\n”;
$output .= ”;
$output .= ”;
$output .= ‘ ‘;
$output .= drupal_get_html_head();
$output .= drupal_get_js();
$output .= ”;
$output .= “”;
$output .= ‘

‘;
$output .= ‘site header‘;
$output .= ‘

‘;
if ($messages) {
$output .= theme(’status_messages’);
}
$output .= $content;
$output .= “

“;
$output .= “

“;
$output .= “”;
return $output;
}

So that was the override of the default maintenence page in the template.php.. Ofcourse, you can add all the styles you want in the maintenence.css…but again, Dont take the trouble for it’s IE7.. you may have to do another maintenence / persuasion page for IE7 might screw up on the CSS again. Feels like heaven to get IE7 out of the way.

Might do some more tweaking.. a filter by navigator.Platform / OS detection as a parallel disparate set that can be operated on with various combos of browsers.. Maybe make it easier for myself to block this stupid linux chauvinist I know