Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 112466

GWMO on "Using do_shortcode() with variables?"

$
0
0

It still didn't seem to work but I may have found the problem. To simplify things, I removed both the "Add to Post" and "Allow PHP in Posts and Pages" plugins and placed the PHP code directly into the single.php template of a child theme - still didn't work. However, when I tried just one of the shortcode options:

<?php echo do_shortcode("[asle id=16]"); ?>

it worked so the problem may be in the conditional or random portion of the code.

I've used WordPress conditional statements befor so that portion of the code looks good to me. Any suggestions on the random array (i.e. if it needs to be changed when I place it into the template)?

<?php if (in_category('Captain America')) {
$id = 0;
while ( ! $id ) {
$id = array_rand( array( 15, 16, 17, 19, 20 ), 1 );
}
echo do_shortcode("[asle id=$id]");
}
?>

Thinking that I will need to make an "If, Then, Else" for each of the 9 categories (characters) on my site - each with it's own random array of 5 possible shortcodes.


Viewing all articles
Browse latest Browse all 112466

Trending Articles