By pol on
Another small website I did for one of my client.
The hardest part was to do a custom page with custom SQL for each pages (Communication, Website, Logotypes and Packaging)
Here is an example of the code I did:
http://www.7340.be/exnihilo/logotypes.exn -> page-node-5.tpl.php
8<.....
<?php print $content ?>
<?php
$num_per_page=9;
$count_query = "SELECT COUNT(term_node.tid)
FROM term_node
JOIN term_data ON term_data.tid = term_node.tid
WHERE term_node.tid
IN (
SELECT term_data.tid
FROM term_data
WHERE vid =6
)
AND term_node.nid
IN (
SELECT nid
FROM node
WHERE TYPE = 'contrat'
)
AND term_node.nid
IN (
SELECT nid
FROM term_node
WHERE tid = '40'
)
";
$result = pager_query("SELECT term_node.tid, term_data.name, GROUP_CONCAT( term_node.nid ) nid
FROM term_node
JOIN term_data ON term_data.tid = term_node.tid
WHERE term_node.tid
IN (
SELECT term_data.tid
FROM term_data
WHERE vid =6
)
AND term_node.nid
IN (
SELECT nid
FROM node
WHERE TYPE = 'contrat'
)
AND term_node.nid
IN (
SELECT nid
FROM term_node
WHERE tid = '40'
)
GROUP BY term_node.tid
ORDER BY name",$num_per_page,0,$count_query);
$i=0;
while ($record = db_fetch_object($result))
{
$node_list = explode(",",$record->nid);
$src[$i] = taxonomy_image_display($record->tid,"onclick='loadme(this)'");
$j=0;
foreach ($node_list AS $nid) {
$node = node_load($nid);
$image = $node->field_image;
$title = $node->title;
$body = $node->body;
$filepath = $image[0]['filepath'];
$subsrc[$i][$j]=theme('imagecache','medium',$filepath,$title,$title,array("class"=>"image"));
$j++;
}
$i++;
}
echo '<script type="text/javascript" charset="utf-8">';
echo "img = new Array();";
echo "infos = new Array();";
if (count($src)>=1) {
foreach ($src as $key => $value) {
preg_match('/src=("[^"]*")/i',$value,$matches);
$src = str_replace("\"","",$matches[1]);
echo "img[{$key}] = '$src';\n";
preg_match('/alt=("[^"]*")/i',$value,$matches);
$alt = str_replace("\"","",$matches[1]);
echo "infos[{$key}] = '$alt';\n";
echo "img_{$key} = new Array();\n";
}
}
if (count($subsrc)>=1) {
foreach ($subsrc as $key => $value) {
foreach ($value as $subkey => $src) {
preg_match('/src=("[^"]*")/i',$src,$matches);
$src = str_replace("\"","",$matches[1]);
echo "img_{$key}[{$subkey}] = '$src';\n";
}
}
}
echo '</script>';
?>
...>8
Those pages have to display taxonomy images in a fancy way and display nodes attached to them as a small icon. Try to click and browse through images...
I will not copy paste the Javascript here, it's a bit long. The Javascript script is used to display the fancy gallery.
Enjoy ;-)
Comments
Noooooooooooooooooo
First off, for anyone reading this post, don't do what's outlined here. Ever. Don't even use it as a template or an example of what to do. Please just move along.
Now, the reason it's bad....
1) There is SQL in a page.tpl.php file. There should never be logic in a *.tpl.php file. They are ONLY for presentation. Anything else is bad form.
2) There is functionality in the theme layer. Functionality does not go in the theme layer but in the module layer.
3) There is inline JavaScript. JavaScript shouldn't be added inline and you just shouldn't see onload="somefunc()" ever being used.
I'm not going to explain how to actually do this (it would take too long). Just highlighting that what's above is not something to be used.
On the other hand...
It does use db_query placeholders properly which is something that many people get wrong...
So, +1 on some elements but -1 in general to the overall solution.
--
Morris Animal Foundation