php - array for multiple categories -
i want make portfolio multiple categories. 1 of 5 similar category pages…
<?php $pagelabel = 'cat1'; include 'cats-config.php'; ?>
the cats-config.php…
<?php include 'cats-arrays.php'; ($i = 0; $i < count($allprojects); $i++) { if (isset($allprojects[$i][$pagelabel])) { include ('thumbs/thumb-' . $allprojects[$i] . '.png'); } } ?>
and lastly cats-arrays.php define project belongs in category…
<?php //for example $allprojects = array( 'project1' => array('cat1', 'cat3', 'cat5'), 'project2' => array('cat2'), 'project3' => array('cat3', 'cat4'), 'project4' => array('cat1', 'cat2', 'cat5'), 'project5' => array('cat2', 'cat3', 'cat4', 'cat5'), 'project6' => array('cat5'), 'project7' => array('cat2', 'cat5'), 'project8' => array('cat1', 'cat3', 'cat4'), ); ?>
doesn't work though, i'm sure something's wrong cats-config.php file.
foreach($allprojects $projectname => $details) { if(in_array($pagelabel, $details)) echo $projectname; }
using foreach make easier read , clean bit. 'in_array' check see if $pagelabel inside of $details, array inside each single column in question in $allprojects.
currently return name of key inside of $allprojects. there can replace echo including images were.
hope helps!
Comments
Post a Comment