Hello
I need a drop down category list on my template.html
I can understand your code but this is for theme.php
How can i do ?
Thanks!!
Since antisa33 emailed me about this I sent her the following reply. Maybe this is usefully to others as well. If it is appropriate to put this into a new thread then please move it.
Ok so here it goes:
In template.html put this
{QUICKJUMP_MENU}
wherever on your pages you want the drop down menu to appear.
In functions.inc.php search the function "load _template()" and add these 2 lines:
$gallery_pos = strpos($template, '{QUICKJUMP_MENU}');
$template = str_replace('{QUICKJUMP_MENU}', quickjumpmenu() ,$template);
Then also in functions.inc.php I have written this function:
function quickjumpmenu() {
global $CONFIG;
global $lang_index_php, $lang_list_categories, $lang_code;
include 'include/album_structure_'.$lang_code.'.php';
$menutxt = '';
if (!($_SERVER['PHP_SELF'] == '/index.php' & (substr($_SERVER['QUERY_STRING'],0,3) == 'lan' | $_SERVER['QUERY_STRING'] == '')) & !($_SERVER['PHP_SELF'] == '/sitemap.php')){
$menutxt .= "<TD align='right'> <Font color='#666666'><select class='listbox_albs' ID='quick_jump' NAME='quick_jump' onchange='document.location=this[this.selectedIndex].value'><OPTION VALUE='' SELECTED> - {$lang_index_php['quick_links']} - </OPTION>";
for ($counter=0; $counter < (count($cnames)); $counter +=1) {
if (count($snames[$cnames[$counter]]) > 1){ // we have sub items
for ($subcounter=0; $subcounter < (count($snames[$cnames[$counter]])); $subcounter +=1) {
$menutxt .= "<OPTION VALUE='/".$slink[$cnames[$counter]][$subcounter]."'>".$cnames[$counter]." - ".$snames[$cnames[$counter]][$subcounter]."</option>";
}
} elseif (count($snames[$cnames[$counter]]) == 1){ // we have only the bw sub items
$menutxt .= "<OPTION VALUE='/".$clink[$counter]."'>".$cnames[$counter]."</option>";
$menutxt .= "<OPTION VALUE='/".$slink[$cnames[$counter]][0]."'>".$cnames[$counter]." - ".$snames[$cnames[$counter]][0]."</option>";
} else {
$menutxt .= "<OPTION VALUE='/".$clink[$counter]."'>".$cnames[$counter]."</option>";
}
}
$menutxt .= "</font></select></td></tr></table>";
}
return $menutxt;
}
The first if condition basically prevents the menu to appear on the front page and on my sitemap. The crucial thing there is the line:
include 'include/album_structure_'.$lang_code.'.php';
so I don't generate the menu on the fly but read in the info from the a file. I decided to do it this way since the album structure is fairly static anyway and if you would do it dynamically then you would have to do a database query whenever someone looks at a page (ontop of all the other queries) which seemed unnecessary. So instead I have six files called album_structure_$lang_code.php' where $lang_code is either "en" "de" etc. for the six languages I have on the site. I generate these files with a php script file that I execute whenever I do some changes in the album structure. The relevant part of this file for you is this:
<?php
/**
File to create the XML files for the Flash movies and also the album structure that is
used in the bottom_txt() function and also in the quickjumpmenu and in the album text
in the flash box.
*/
define('IN_COPPERMINE', true);
define('INDEX_PHP', true);
require('include/init.inc.php');
global $CONFIG, $lang_code;
pageheader('Update XML and album structure');
echo '</tr></table>';
starttable(690, 'Make XML files');
echo '<TR><TD CLASS="order">';
update_albums();
echo '</TD></TR"></Table>';
ob_end_flush();
/*
End of Main code
*/
/*
UPDATE ALBUM STRUCTURE
*/
function update_albums() {
global $CONFIG, $lang_code;
$selected_lang=$lang_code;
$langs = array('en','fr','de','it','es','pt');
for ($langcount=0; $langcount < 6; $langcount++) {
$all = '';
$cnames = '';
$clink = '';
$snames = '';
$slink = '';
$toplevel = '';
$topalblocs = '';
$salblocs = '';
$lnk_txt = '';
$lang_code=$langs[$langcount];
$sql = "SELECT title FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid= 19"; //USA for bw New York album
$esult = db_query($sql);
$USA=mysql_fetch_array($esult);
mysql_free_result($esult);
$sql = "SELECT cid,name FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid > 1 AND parent = 0 ORDER by pos"; // top level categories (not used)
$esult = db_query($sql);
$count=0;
while ($rrrow = mysql_fetch_array($esult, MYSQL_NUM)) {
$sql = "SELECT name,cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent=$rrrow[0]";
$result = db_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$cnames[$count] = bb_decode($row[0]);
$clink[$count] = 'category_'.$row[1];
$topalblocs[$count] = '';
$toplevel[$count] = $rrrow[0];
$sql = "SELECT title,aid,description FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $row[1]";
$rresult = db_query($sql);
$sub_count=0;
while ($rrow = mysql_fetch_array($rresult, MYSQL_NUM)) {
$snames[$cnames[$count]][$sub_count] = bb_decode($rrow[0]);
$slink[$cnames[$count]][$sub_count] = 'album_'.$rrow[1];
$salblocs[$cnames[$count]][$sub_count] = stripos(bb_decode($rrow[2]),'<i>') ? substr(bb_decode($rrow[2]), 0 , stripos(bb_decode($rrow[2]),'<i>')) : bb_decode($rrow[2]);
$sub_count=$sub_count+1;
}
array_multisort($snames[$cnames[$count]],$slink[$cnames[$count]],$salblocs[$cnames[$count]]);
$count=$count+1;
mysql_free_result($rresult);
}
$sql = "SELECT title,aid,description FROM {$CONFIG['TABLE_ALBUMS']} WHERE category=$rrrow[0]";
$result2 = db_query($sql);
while ($row = mysql_fetch_array($result2, MYSQL_NUM)) {
if ($rrrow[0]==2 && $row[1]>1 && $row[1]!=5) { //bw
$snames[bb_decode($row[0])][count($snames[bb_decode($row[0])])] = bb_decode($rrrow[1]); // we don't use [0] here so the bw gets sorted after the colour albums
$slink[bb_decode($row[0])][count($slink[bb_decode($row[0])])] = 'album_'.$row[1];
$salblocs[bb_decode($row[0])][count($slink[bb_decode($row[0])])-1] = stripos(bb_decode($row[2]),'<i>') ? substr(bb_decode($row[2]), 0 , stripos(bb_decode($row[2]),'<i>')) : bb_decode($row[2]);
} elseif ($row[1]==5) {
$snames[bb_decode($USA[0])][0] = bb_decode($row[0]).' ('.bb_decode($rrrow[1]).')';
$slink[bb_decode($USA[0])][0] = 'album_'.$row[1];
$salblocs[bb_decode($USA[0])][0] = stripos(bb_decode($row[2]),'<i>') ? substr(bb_decode($row[2]), 0 , stripos(bb_decode($row[2]),'<i>')) : bb_decode($row[2]);
} else { // top level albums
$cnames[$count] = bb_decode($row[0]);
$clink[$count] = 'album_'.$row[1];
$toplevel[$count]= $rrrow[0];
$topalblocs[$count] = stripos(bb_decode($row[2]),'<i>') ? substr(bb_decode($row[2]), 0 , stripos(bb_decode($row[2]),'<i>')) : bb_decode($row[2]);
}
$count=$count+1;
}
}
// Do the link from each category (albums not implemented yet)
$sql = "SELECT cid,Link_txt FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1";
$link_result = db_query($sql);
while ($row = mysql_fetch_array($link_result, MYSQL_NUM)) {
$lnk_txt[$row[0]] .= trim($row[1]);
}
array_multisort($cnames,$clink,$toplevel,$topalblocs);
$all = "<?php \r\n";
$all .= '$cnames = ' . var_export($cnames, true) . "; \r\n";
$all .= '$clink = ' . var_export($clink, true) . "; \r\n";
$all .= '$snames = ' . var_export($snames, true) . "; \r\n";
$all .= '$slink = ' . var_export($slink, true) . "; \r\n";
$all .= '$toplevel = ' . var_export($toplevel, true) . "; \r\n";
$all .= '$topalblocs = ' . var_export($topalblocs, true) . "; \r\n";
$all .= '$salblocs = ' . var_export($salblocs, true) . "; \r\n";
$all .= '$clink_txt = ' . var_export($lnk_txt, true) . "; \r\n";
$all .= '?>';
$outfile = 'include/album_structure_'.$lang_code.'.php';
$handle = fopen($outfile,"w");
fwrite($handle,$all);
if (fclose($handle)) echo 'Language: '.$lang_code.' completed Successfully!' . "\r\n";
} // end of loop through languages
}
Now this last function is very specific for the particular album structure I have so it looks really messy. But I hope you can modify it for your purposes. If your structure is more straightforward, you might be able to get away with just 1 or 2 mysql queries. Hope this helps.