0

I'm writing a WP theme, and I want the main content area to change width based on whether there's an active sidebar or not. To make this easier, I'm using bootstrap.

The problem is that the output is blank.

Here's the code I'm trying to use to do the calculations:

<!-- Calculate content width based on sidebars -->
<?php
if ( is_active_sidebar( 'left_sidebar' ) && !is_active_sidebar( 'right_sidebar' ) ) {
	$mainspan = "9";
}
?>
<?php
if ( !is_active_sidebar( 'left_sidebar' ) && is_active_sidebar( 'right_sidebar' ) ) {
	$mainspan = "span9";
}
?>
<?php
if ( is_active_sidebar( 'left_sidebar' ) && is_active_sidebar( 'right_sidebar' ) ) {
	$mainspan = "span6";
}
?>
<?php
if ( !is_active_sidebar( 'left_sidebar' ) && !is_active_sidebar( 'right_sidebar' ) ) {
	$mainspan = "span12";
}
?>

The result should be loaded here, but I get a blank value:

<main class="<?php echo $mainspan; ?>">

4

1 回答 1

0

Andrewsi asked if there were any includes in the file. That lead me to realize that the code itself was functional, but was not working because one was being included into the other. The IF statements were written in the Header.php, which was included into the Index.php where the variable call was located. Placing the IF statements into the Index.php fixed the issue.

于 2016-04-24T20:21:40.587 回答