sidebar.php if, else if, else php
-
I am getting a syntax error with this code and I’m not sure what I’m doing wrong. I want to have a standard sidebar for most pages, except the home page and Blog. The name of my blog page in my admin > pages is “Blog”.
<div class="sidebar1" class="fluid-sidebar sidebar span4" role="complementary"> <?php if ( is_front_page() ) : ?> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homesidebar') ) : ?> <?php elseif ( is_page(Blog) ) : ?> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?> <?php else : ?> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('othersidebar') ) : ?> <?php endif ; ?> </div>
[forum guidelines for marking code – http://codex.wordpress.org/Forum_Welcome#Posting_Code ]
Any ideas? Thanks.
-
When nesting if-statements I suggest you use curly braces instead that makes the code a lot more readable. This will probably fix whatever syntax error is in there.
if ( is_front_page() ) { if ( !function_exists('dynamic_sidebar') || dynamic_sidebar('homesidebar') ) { } } elseif ( is_page(Blog) ) { if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) { } } else { if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('othersidebar') ) { } }
is_page(Blog)
is supposed to be
is_page( ‘Blog’ )
Thanks. I figured it out, but would like to use the syntax as you do.
So do I need to proceed it with:
<?php
What dotnordic showed in your post
and end with
: ?>Here’s How I fixed it. I was missing the end if statements
<div id="sidebar1" class="fluid-sidebar sidebar span4" role="complementary"> <?php if ( is_page('Blog') ) : ?> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?><?php endif ; ?> <?php elseif (is_page()) : ?> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('othersidebar') ) : ?> <?php endif ; ?> <?php else : ?> <!-- This content shows up if there are no widgets defined in the backend. --> <div class="alert alert-message"> <p><?php _e("Please activate some Widgets","bonestheme"); ?>.</p> </div> <?php endif; ?> </div>
The problem I am still having is that the sidebar is getting the fluid sidebar css that is making it 30% width, but them it is doing it again for the widgets.
the sidebar is getting the fluid sidebar css that is making it 30% width, but them it is doing it again for the widgets
for formatting problems, please post a link to the site.
btw:
this part is redundant in all sidebar codes, and can easily be omitted:
!function_exists('dynamic_sidebar') ||
(because the function was introduced about wp2.2, i.e. many versions ago)
I’m sorry I am not adept with php. Can you tell me what/where I do with this: “!function_exists(‘dynamic_sidebar’) ||”
you can leave it where it is – it won’t do any harm, it is just redundand;
or remove it like:
<div id="sidebar1" class="fluid-sidebar sidebar span4" role="complementary"> <?php if ( is_page('Blog') ) : ?> <?php if ( !dynamic_sidebar('sidebar1') ) : ?><?php endif ; ?> <?php elseif (is_page()) : ?> <?php if ( !dynamic_sidebar('othersidebar') ) : ?> <?php endif ; ?> <?php else : ?> <!-- This content shows up if there are no widgets defined in the backend. --> <div class="alert alert-message"> <p><?php _e("Please activate some Widgets","bonestheme"); ?>.</p> </div> <?php endif; ?> </div>
Thanks!
- The topic ‘sidebar.php if, else if, else php’ is closed to new replies.