I’m a PHP amateur, so please bear with me. ?
[code=php]<?php
if (get_category(‘1’)->category_count == 1) {
$blah = “‘numberposts=3&cat=-1′”;
}
elseif (get_category(‘1’)->category_count > 1) {
$blah = “‘numberposts=2&cat=-17”;
}
else {
$blah = “‘numberposts=4&cat=-1′”;
}
global $post;
$myposts = get_posts($blah);
foreach($myposts as $post) :
setup_postdata($post);
?>
———-stuff to display each post———-
<?php endforeach; ?>
Some may recognise this as coming from a WordPress template, but I think this is primarily a PHP-related question. Essentially what I’m trying to do is to modify this line depending on the result of the if/elseif/else statement:
[COLOR=”DarkRed”]$myposts = get_posts(‘numberposts=[X]&cat=-1’)
So if the first condition holds (category count = 1), then I want to have:
[COLOR=”DarkRed”]$myposts = get_posts(‘numberposts=3&cat=-1’)
And so on. Based on testing, the above block of code isn’t working: the $blah isn’t being substituted into the $myposts line. How would I go about making this work? This may well be some embarrassing mistake, so apologies in advance if it is. ?