Complete newbie to programming 🙂
i am fiddling around with a WordPress theme and hit a roadblock. If i put this in archive.php,
<?php
if (is_category(array( 9, 13, 24,)) {
echo 'Light is GREEN';
}else {
echo 'Light is RED}';
?>
That part works fine, when i go to category 9, 13, 24 i get “light is Green” and “light is red” for all other categories.
Now i have this function which gets the id’s of categories from theme options where i need to echo “light is green”
function am_get_cat_layout_ids()
{
global $am_option;
$catnumend = $am_option['main']['category_onecolumn_hidden']-1;
for($i=0; $i<$catnumend; $i++)
{
$value = $am_option['main']['category_onecolumn_'.$i].',';
}
return $value;
}
if i echo $value instead of return, i get the category id’s say 2, 15, 7, 34, fine but if i do this :
<?php
if (is_category(array(am_get_cat_layout_ids())) {
echo 'Light is GREEN';
}else {
echo 'Light is RED}';
?>
its not working.
anything that can be done to make it work?
Thank you ,
Srik
Try this:
and
If your
am_get_cat_layout_ids()
function returns2, 15, 7, 34,
then you should do:What you have made is an array containing one string, which has comma-separated numbers. You want to build an array of numbers.
Your original code was the equivalent to this:
Whereas this new code is the equivalent to the code at the beginning of the question: