WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional tag and parse error (8 posts)

  1. Nessdufrat
    Member
    Posted 5 years ago #

    Hi !
    I'm trying to set different sidebars according to which page the user is on.
    I did that :

    <?
    if is_page('8')
    {
    function_exists('dynamic_sidebar') && dynamic_sidebar(2)
    }
    if is_page('7')
    {
    function_exists('dynamic_sidebar') && dynamic_sidebar(1)
    }
    endif; ?>

    and on my page.php template,

    <? get_sidebar(); ?>

    I get a parse error, unexpected T string on line 2 on the sidebar.php.

    "Parse error: syntax error, unexpected T_STRING, expecting '(' "

    Can't understand what's wrong. Help would be greatly appreciated !

  2. tech_coach
    Member
    Posted 5 years ago #

    Hi,

    Your second "if" should be "elseif" and you should have an else (even if it's blank).

    <?
    if is_page('8')
    {
    function_exists('dynamic_sidebar') && dynamic_sidebar(2)
    }
    elseif is_page('7')
    {
    function_exists('dynamic_sidebar') && dynamic_sidebar(1)
    }
    else {
    	// blank - do not show a sidebar
    }
    
    endif; ?>
  3. Nessdufrat
    Member
    Posted 5 years ago #

    Actually, I did something different because my code was completly false from the beginning.

    Here is the right version :

    <div class="sidebar">
    <?
    if( function_exists( 'dynamic_sidebar' ) )
    {
    	switch ( is_page( $post->ID ) )
    	{
    		case "8":
    		{
    			dynamic_sidebar( 2 );
    			break;
    		}
    
    		case "7":
    		{
    			dynamic_sidebar( 1 );
    			break;
    		}
    	}
    }
    ?>
    
    </div>
  4. tech_coach
    Member
    Posted 5 years ago #

    cool! So it works now?

  5. Nessdufrat
    Member
    Posted 5 years ago #

    Yeah :) A friend (C# programmer) helped me write this, and it works like a charm !

  6. bjovanov85
    Member
    Posted 5 years ago #

    I can't do anything on my site. I can't get to dashboard because whenever I type my URL in this comes up.

    Parse error: syntax error, unexpected T_STRING in /home/thescri1/public_html/wp-includes/functions.php on line 1208

    Someone please help!

  7. asechrest
    Member
    Posted 5 years ago #

    Did you change some code in your functions.php file?

  8. bjovanov85
    Member
    Posted 5 years ago #

    No, it just happened out of nowhere. One day it just didn't work.

Topic Closed

This topic has been closed to new replies.

About this Topic