4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Eagle Eye on April 03, 2006, 03:56:32 PM

Title: Getting cat ID
Post by: Eagle Eye on April 03, 2006, 03:56:32 PM
I have been searching for weeks a small post by Jan on how to use cat ID for some work in gallery…
unfortunately I cannot find it…  :?

I wanted to make the following loop…
So how do I make the following code correct?

============================================
$id = {cat_id};

if ($id == "2") {
include(ROOT_PATH.'some_file1.php')
}

if ($id == "3") {
include(ROOT_PATH.'some_file2.php')
}

==============================================

Thanks :D
Title: Re: Getting cat ID
Post by: IcEcReaM on April 03, 2006, 05:35:45 PM
$id = {cat_id};

should be like: $id = $cat_id
you can't use {cat_id} in the php file,
cause their only parsed in templates.
Title: Re: Getting cat ID
Post by: Eagle Eye on April 03, 2006, 05:43:31 PM
$id = {cat_id};

should be like: $id = $cat_id
you can't use {cat_id} in the php file,
cause their only parsed in templates.

Thanks, i know that we cannot use "{cat_id}" in php file, what i meanto ask was what is the correct synatax to be placed so that i can get the same info as {cat_id} would give in templates... thanks ;) i will check it out...
Title: Re: Getting cat ID
Post by: IcEcReaM on April 03, 2006, 05:59:43 PM
ah i forget.
if you got a lot of different ids:
instead of:

if ($id == "2") {
include(ROOT_PATH.'some_file1.php')
}

if ($id == "3") {
include(ROOT_PATH.'some_file2.php')
}

you can use switch.

for example:
switch($id) {
 case 3:
    include(ROOT_PATH.'some_file2.php');
    break;
 case 4:
 ....

}
Title: Re: Getting cat ID
Post by: V@no on April 04, 2006, 12:36:52 AM
Or another solution:
Code: [Select]
if (in_array($cat_id, array(2,3,4,5,10,8)))
{
  include(ROOT_PATH.'some_file'.$cat_id.'.php');
}
Only usefull if you want to have independed "some_fileXX.php" for each category
and if you want to "share" one file for more then one category:
Code: [Select]
$ids = array( //first number is category id, second number is file number
  2 => 1,
  3 => 2,
  4 => 1,
  5 => 3,
  10 => 4,
  8 => 2,
);
if (isset($ids[$cat_id]))
{
  include(ROOT_PATH.'some_file'.$ids[$cat_id].'.php');
}