different header image for each category? different header image for each category?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

different header image for each category?

Started by wuschel_lux, May 21, 2007, 11:06:47 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

wuschel_lux

Hi,

I searched the forum to fin a hint to realize my project but I didn't realy found something.

I am working now on my project www.volleyball.lu. I have 5 different categories in the gallery. Now I want to have for each category a different header image. Normally this will not be a too great problem for me to code it in PHP, but in this case the template.html ist a HTML file.

Can someone give me a hint how to "include" a PHP script in the template file?

Tanks in advance

Joachim Müller

That's what the custom_header feature is meant to be used for.

wuschel_lux

Thanks GauGau for the hint an the perfect support on this site,

I will try to implement this this evening.

Regards

wuschel_lux

so I tested the {Custom Header} and it works nearly fine.
- I got my header image
- got the $cat ID
- but I cant use the {LOGIN_FORM} in my header.php

What must I change to the code that it will be accepted?

Can somebody help me.

Thanks

Joachim Müller

The placeholder tokens in curly brackets get replaced when the template is being run. You can't use those placeholders outside of template.html.

For details, post details (link to your gallery, your code changes (attach your zipped theme and your custom include).

wuschel_lux

In this case its not so easy i thought. Here are more detailed infos:
- URL www.volleyball.lu/fotogallery
- Coppermine Photo Gallery 1.4.10 modpack
- Theme Oranje (modified a bit ...)

NOTE: The header.php is not the final version, was just quick and dirty to test. I will have to make DB querys to get from pic, the album id and category id.

I attached the files in the Oranje.zip with all theme files.

I hope this will help.

Thanks

Joachim Müller

OK, here's the content of your header include:<?php
        $cat 
$_GET["cat"];
        
//echo 'category = '.$cat;

        
switch ($cat) {
        case 
2:
                
$headIMG "logo_indoor.png";
                    
//echo "indoor";
                    
break;
        case 
3:
                
$headIMG "logo.png";
                    
//echo "beach";
                    
break;
        case 
4:
                
$headIMG "logo.png";
                    
//echo "archiv";
                    
break;
        case 
8:
                
$headIMG "logo.png";
                    
//echo "fun";
                    
break;
        case 
9:
                
$headIMG "logo.png";
                    
//echo "events";
                    
break;
        default:
                
$headIMG "logo.png";
                    
//echo "standard";
}
?>


         <tr>
          <td width="760" height="120" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/<?php echo $headIMG?>);">
        <table cellpadding="0" cellspacing="3" border="0" width="100%"><tr>
                        <td align="right">
                        <!-- <h1> {GAL_NAME}</h1>{GAL_DESCRIPTION} --> <br /><br /><br /><br /><br />
                        <font color="#ffffff">{LOGIN_FORM}</font><span style="font-size: 8px;"><br /></span>
                </td></tr></table>
      </td>
          </tr>
Why do you want to move stuff from template.html into it. Move         <tr>
          <td width="760" height="120" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/<?php echo $headIMG?>);">
        <table cellpadding="0" cellspacing="3" border="0" width="100%"><tr>
                        <td align="right">
                        <!-- <h1> {GAL_NAME}</h1>{GAL_DESCRIPTION} --> <br /><br /><br /><br /><br />
                        <font color="#ffffff">{LOGIN_FORM}</font><span style="font-size: 8px;"><br /></span>
                </td></tr></table>
      </td>
          </tr>
back into themes/yourtheme/template.html, leaving header.php with only<?php
        $cat 
$_GET["cat"];
        
//echo 'category = '.$cat;

        
switch ($cat) {
        case 
2:
                
$headIMG "logo_indoor.png";
                    
//echo "indoor";
                    
break;
        case 
3:
                
$headIMG "logo.png";
                    
//echo "beach";
                    
break;
        case 
4:
                
$headIMG "logo.png";
                    
//echo "archiv";
                    
break;
        case 
8:
                
$headIMG "logo.png";
                    
//echo "fun";
                    
break;
        case 
9:
                
$headIMG "logo.png";
                    
//echo "events";
                    
break;
        default:
                
$headIMG "logo.png";
                    
//echo "standard";
}
?>
in it.

wuschel_lux

thanks for your reply

but I dont understand how I can use <?php echo $headIMG; ?> in a .html file as you mentioned to not copy the table structure to the header.php file.


Joachim Müller

Ah OK, sorry for not looking more carefully.

header.php:<tr>
          <td width="760" height="120" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/
<?php
        $cat 
$_GET["cat"];
        
//echo 'category = '.$cat;

        
switch ($cat) {
        case 
2:
                
$headIMG "logo_indoor.png";
                    
//echo "indoor";
                    
break;
        case 
3:
                
$headIMG "logo.png";
                    
//echo "beach";
                    
break;
        case 
4:
                
$headIMG "logo.png";
                    
//echo "archiv";
                    
break;
        case 
8:
                
$headIMG "logo.png";
                    
//echo "fun";
                    
break;
        case 
9:
                
$headIMG "logo.png";
                    
//echo "events";
                    
break;
        default:
                
$headIMG "logo.png";
                    
//echo "standard";
}

echo 
$headIMG;
?>


Back into template.html:        <table cellpadding="0" cellspacing="3" border="0" width="100%"><tr>
                        <td align="right">
                        <!-- <h1> {GAL_NAME}</h1>{GAL_DESCRIPTION} --> <br /><br /><br /><br /><br />
                        <font color="#ffffff">{LOGIN_FORM}</font><span style="font-size: 8px;"><br /></span>
                </td></tr></table>
      </td>
          </tr>

wuschel_lux

thanks for your hint with splitting the code, now it works fine, I just have to code the category DB querry's.

When I finishe I will post the final code.

thanks for the great support

Joachim Müller

OK, great.
Another side-note: coppermine already populates the variable named $cat. So either use the one populated by coppermine or choose another name for your custom variable.

wuschel_lux

Quote from: GauGau on May 22, 2007, 12:52:57 PM
OK, great.
Another side-note: coppermine already populates the variable named $cat. So either use the one populated by coppermine or choose another name for your custom variable.
I did it already, named it $catID

wuschel_lux

I coded now the SQL querry, the header per category works fine  :) but I got an other big problem, when activating header.php  ???

When I click on the e.g. most viewed menu point I will get following error message:
Unknown column 'topn' in 'where clause'

What did I wrong? If I comment the SQL querry, it works again without error...

Can somebody help me. Thanks

Here my code:
<?php
        $mycatID   
$_GET["cat"];
$myalbumID $_GET["album"];
        
//echo 'category = '.$mycatID.'; album = '.$myalbumID;

if($myalbumID >= "0")
{
$sqlID 'SELECT `category` FROM `cpg1410_albums` WHERE `aid` = '.$myalbumID.' ';
$resultID mysql_query($sqlID) OR die(mysql_error());
while($rowID mysql_fetch_assoc($resultID)) {
$mycatID $rowID['category'];
        
//echo '; calculated category = '.$rowID['category'];
    
}

else
{$mycatID $mycatID;}

        switch (
$mycatID) {
        case 
2:
                
$headIMG "logo_indoor.png";
                    break;
        case 
3:
                
$headIMG "logo.png";
                    break;
        case 
4:
                
$headIMG "logo.png";
                    break;
        case 
8:
                
$headIMG "logo.png";
                    break;
        case 
9:
                
$headIMG "logo.png";
                    break;
        default:
                
$headIMG "logo.png";
}

?>

<tr>
          <td width="760" height="120" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/<?php echo $headIMG?>);">



Joachim Müller

The variable "$album" is not only being populated with actual album IDs (i.e. numbers), but with the short names for meta albums as well. Subsequently, if you visit a meta album like best rated or most viewed, the query will fail. Add a check after $myalbumID = $_GET["album"];that checks if $myalbumID is an integer. If it isn't, return the default header image without running the query. You have to be careful with your script: the $_GET array is being populated by the end user. If you use it, you'll have to sanitize the data before using them.

I'm not sure though why you need to run a query of your own - why don't you used the existing vars and functions?

Anyway, this is going beyond regular Coppermine support...

wuschel_lux

Quote from: GauGau on May 22, 2007, 01:52:42 PM
I'm not sure though why you need to run a query of your own - why don't you used the existing vars and functions?
I am not sure that I must use a query, but for my understanding I found no other way to do it.

To get the category from the main page, I used the variable $cat.
But after if I am inside of an album I dont even have this variable filled. So I made the query with the album ID to find again the category ID.
How can I use the existing vars and functions?

I will try to rewrite the code with your tips ...

Thanks

wuschel_lux

Thanks a lot GauGau.
After applying your tips the script seems to work perfekt. If it is the best way to do? I dont know, but it works and the result is what I want.
If sombody has a better solution, pleas share it with us.

So here again the code:
<?php
        $mycatID   
$_GET["cat"];
$myalbumID $_GET["album"];

//echo 'category = '.$mycatID; // OUTPUT VAR TEST

if (ereg("^[0-9]+[.]?[0-9]*$"$myalbumID$p)) {
$checkINT 1// is INT
} else {
$checkINT 0// is not INT
}


        if(
$checkINT == "1" && $myalbumID >= "0")
{
$sqlID 'SELECT `category` FROM `cpg1410_albums` WHERE `aid` = '.$myalbumID.' ';
$resultID mysql_query($sqlID) OR die(mysql_error());
while($rowID mysql_fetch_assoc($resultID)) {
$mycatID $rowID['category'];
    
}

else
{$mycatID $mycatID;}

        switch (
$mycatID) {
        case 
2:
                
$headIMG "logo_indoor.png";
                    break;
        case 
3:
                
$headIMG "logo.png";
                    break;
        case 
4:
                
$headIMG "logo.png";
                    break;
        case 
8:
                
$headIMG "logo.png";
                    break;
        case 
9:
                
$headIMG "logo.png";
                    break;
        default:
                
$headIMG "logo.png";
}
//echo '; album = '.$myalbumID.'; calculated category = '.$mycatID.'; is INT? = '.$checkINT; // OUTPUT VAR TEST
?>

<tr>
          <td width="760" height="120" valign="top" align="center"  style="padding-right:10px; background-repeat: no-repeat; background-position: center left; background-image:url(themes/oranje/images/<?php echo $headIMG?>);">

Joachim Müller