• Resolved jamCincinnati

    (@jamcincinnati)


    In my site I have two different sidebars, one for the Blog and one for the rest of the site.

    The sidebars reside in php files named sidebar-blog.php and sidebar-standard.php.

    Here is the code:

    <?php
    		if ( is_home( 'blog' )) : {
        			// This is the blog sidebar
        			get_sidebar( 'blog' );
    		} else {
        			// This is the sidebar for website
        			get_sidebar( 'standard' );
    		}
    		?>

    The following error appears when I try to access the Blog page:

    Parse error: syntax error, unexpected ‘{‘, expecting ‘:’ in /home/graphic6/public_html/artist_site/wp-content/themes/doublechild/index.php on line 62

    When accessing the other pages I get the blog sidebar.

    (The homepage has no sidebar and is unaffected)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The IF statement is coded wrong. Have a “:” that shouldn’t be there.

    <?php
    		if ( is_home( 'blog' )) {
        			// This is the blog sidebar
        			get_sidebar( 'blog' );
    		} else {
        			// This is the sidebar for website
        			get_sidebar( 'standard' );
    		}
    		?>

    There are several ways to code an IF statement but you can’t mix them together: http://php.net/manual/en/control-structures.if.php

    Is this line 62:

    if ( is_home( 'blog' )) : {

    You’re mixing the two different if/else PHP styles. Since you’re already using the bracketed style, try this instead:

    if ( is_home( 'blog' ) ) {

    Thread Starter jamCincinnati

    (@jamcincinnati)

    Mark, Stephen, thanks for the help.

    The statement works but not quite the way I expected.

    The blog sidebar shows up on all pages, not just the blog. After fooling with it for a day and a half I was just sitting staring at the code on the screen and listening to music (Nightwish, Wishmaster album) when I realized the blog sidebar is called from index.php and on the other pages it is called by page.php. DUH!

    No wonder half of my hair ends up on the floor when I try code this.

    Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP if statement not working’ is closed to new replies.