Hi,
I've been searching high and low for how to do this for hours to no avail.
I'm coding a plugin where my goal is to allow someone to place "whatever" on single posts based on category id's that they specify.
Scenario
------------
Place Google Adsense on post of these categories:
In the widget options I provide a field to define category id's (comma separated):
<!-- Multiple Category ID's -->
<p>
<?php echo '<label for="' . $this->get_field_name('gaw_placebymcat') . '">' . __(' Multiple Categories by ID:') . '
<input style="width:25%;" id="' . $this->get_field_id('gaw_placebymcat') . '" name="' . $this->get_field_name('gaw_placebymcat') . '"
type="text" value="' . $gaw_placebymcat . '" /></label>'; ?>
</p>
So lets say their input is 6,11,17 - the person would want the widget (adsense ads) to display on all post in the categories 6,11, and 17.
So I got the conditional tag in_category to correct return true or false based on the current posts categories by hard-coding the array as normal:
if (in_category( array( '6', '11', '17' ) ) ) { echo 'display ads her because this is cat 6, 11 or 17';} else {echo 'we wont display because condition is false';}
So I confirmed this as working. So it looks like I need an array like in the code above. So I looked how to create an array from a comma separated string and came up with this:
$multicats = $gaw_placebymcat;
//the variable is user defined cats sep'd by commas
// split to array
$multicatarray = explode(', ', $multicats);
print_r($multicatarray);
The result:
Array ( [0] => 6,11,17 )
But I don't think this what I want, and I have know idea how to incorporate that into the in_category condition. Again, I'm pretty new to PHP and a bit of a hack I guess that's how you learn :)
Anyway, I'm so hard-headed I worked on this for 8 hours before asking here.
Hope one of you can point in the right direction. Maybe I'm totally turned around here.
So please, please help me!
Thanks a bunch,
Bryan