Determine category number within index template (index.tpl)
Moderator: Thorsten
Determine category number within index template (index.tpl)
Back with another one...
Hi, I'm trying to change the banner/header depending on which category you are in. I'm using Apache2Triad dev server on XP dev box.
On my local server I could get the cat number from the url by doing this:
<?php
switch ($_GET['cat'])
{
case 1:
print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 2:
print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 3:
print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 4:
print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
default:
print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
}
?>
All was working fine, but when I upload it to my live server the script bombs. So the question is: Is there a way to determine which category you are in from the index template? Is there a way to insert case statement in the index.tpl
eg.
$catNum = x;
where x is the category number of the section your are in.
Cheers
Nat
Hi, I'm trying to change the banner/header depending on which category you are in. I'm using Apache2Triad dev server on XP dev box.
On my local server I could get the cat number from the url by doing this:
<?php
switch ($_GET['cat'])
{
case 1:
print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 2:
print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 3:
print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 4:
print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
default:
print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
}
?>
All was working fine, but when I upload it to my live server the script bombs. So the question is: Is there a way to determine which category you are in from the index template? Is there a way to insert case statement in the index.tpl
eg.
$catNum = x;
where x is the category number of the section your are in.
Cheers
Nat
Re: Determine category number within index template (index.t
Hi,

bye
Thorsten
what happens exactly?natmanu wrote:All was working fine, but when I upload it to my live server the script bombs.
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Hi,
I've managed to get the script to work but it now displays error when it branches to the default case statement. see:
http://www.uvolunteer.org/faqs/index.php
It seems to work when cat = a number !
2. I'm also having problem with include files inserted into index.tpl
What is the path to the include dir if my include directory from document root is: www.uvolunteer.org/includes/
I've tried '/includes/filename.php' or relative to the index.tpl '../../includes/filename.php' but it errors that it cannot find file.
Cheer
Nat
I've managed to get the script to work but it now displays error when it branches to the default case statement. see:
http://www.uvolunteer.org/faqs/index.php
It seems to work when cat = a number !
2. I'm also having problem with include files inserted into index.tpl
What is the path to the include dir if my include directory from document root is: www.uvolunteer.org/includes/
I've tried '/includes/filename.php' or relative to the index.tpl '../../includes/filename.php' but it errors that it cannot find file.
Cheer
Nat
Hi,
the code have to look like:
bye
Thorsten
the code have to look like:
Code: Select all
<?php
if (isset($_GET['cat']) && is_int($_GET['cat'])) {
switch ($_GET['cat']) {
case 1:
print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 2:
print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 3:
print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 4:
print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
default:
print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
}
}
?> Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Hi,
you should try the path '../includes/filename.php'.
bye
Thorsten
you should try the path '../includes/filename.php'.
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
hi,
The conditon you wrote outputs nothing! I've modified it to contain an else conditon to test it and it always evaluates false although cat is get. you test it here, click on the right nav to see results:
www.uvolunteer.org/faqs
<?php
if (isset($_GET['cat']) && is_int($_GET['cat'])) {
switch ($_GET['cat']) {
case 1:
print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 2:
print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 3:
print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 4:
print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
default:
print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
}
} else {
echo "The statement evaluated to false".' and $GET = '.$_GET['cat'];
}
?>
The conditon you wrote outputs nothing! I've modified it to contain an else conditon to test it and it always evaluates false although cat is get. you test it here, click on the right nav to see results:
www.uvolunteer.org/faqs
<?php
if (isset($_GET['cat']) && is_int($_GET['cat'])) {
switch ($_GET['cat']) {
case 1:
print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 2:
print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 3:
print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
case 4:
print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
default:
print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">";
break;
}
} else {
echo "The statement evaluated to false".' and $GET = '.$_GET['cat'];
}
?>
Hi Nat,
I'd suggest you to change the way of working: just add a new key {key} in the template and manage it within index.php: the template has currently no access to HTTP GET parameters.
Let me check this proposal and back here with a code sample.
You should use:natmanu wrote: } else {
echo "The statement evaluated to false".' and $GET = '.$_GET['cat'];
}?>
Code: Select all
...
} else {
echo "The statement evaluated to false";
}Let me check this proposal and back here with a code sample.
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Amazon.co.uk Wishlist
Hi Nat,
back again with another different solution
Matteo
back again with another different solution
- Use this code below for index.tpl:
Code: Select all
... <?php if (isset($cat) && is_numeric($cat)) { switch ($cat) { case 1: print "<img src=\"../../images/faq_header_gen.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">"; break; case 2: print "<img src=\"../../images/faq_header_bo.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">"; break; case 3: print "<img src=\"../../images/faq_header_cr.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">"; break; case 4: print "<img src=\"../../images/faq_header_ec.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">"; break; default: print "<img src=\"../../images/faq_header.jpg\" width=\"595\" height=\"201\" alt=\"\" border=\"0\">"; break; } } ?> ... - Locate, open and backup the inc/parser.php file and change these lines below:in:
Code: Select all
... function processTemplate($templateName, $myTemplate) { global $PMF_CONF; ...Code: Select all
... function processTemplate($templateName, $myTemplate) { global $PMF_CONF; // Expose some PMF variables to the template global $cat; ...
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Amazon.co.uk Wishlist