• Resolved JaanMatti

    (@jaanmatti)


    Hey, guys! I’m having a really annoying problem with a bit of a PHP code, that probably is easy. I’m just quite a beginner at PHP and trying to get the hang of it in wordpress.

    What I want to do, is to display a higher banner (default) on the home page and then a smaller one (custom made in a div) on all the other pages.

    The address for the site: https://uus.kaaskiri.ee (to see what it looks like right now – because of the faulty code, it displays both the default banner and the lower one.)

    The code: (banner.php file)

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Can anyone spot what’s wrong here? I’d be really grateful!

    Jaan-Matti

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Please don’t post large code excerpts in the forums, it makes the spam filter unhappy.

    Please post your code up on pastebin.com and link to it. It LOOKS like you just have some php calls outside of <?php ?> tags is all.

    Thread Starter JaanMatti

    (@jaanmatti)

    Hey!

    I uploaded the code on pastebin:

    https://pastebin.com/NP7G085t

    Ipstenu, I’m sure that the case may be in some calls being outside of <?php ?> tags, but it seems I don’t really understand what to change and where…

    Pastebin link not working !

    Try this one:

    <?php if (is_front_page()) {
    
        global $options;
        foreach ($options as $value) {
            if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
    
        if ($gear_banner_visibility == "on") { ?>
                        <div class="banner">
                            <div class="paddings">
                                <img src="<?php bloginfo('stylesheet_directory'); ?>/images/ico.big/<?php echo $gear_banner_image; ?>" alt="Gear"></img>
                                <?php echo stripslashes($gear_banner_text); ?>
                            </div>
                            <div class="clear"></div>
                        </div>
    					<?php } } 
    
    } else {
    
    echo '<div id="menubottom"></div>';
    
    }
    ?>
    Thread Starter JaanMatti

    (@jaanmatti)

    Going with a second try:

    https://pastebin.com/6RZ5WLQC

    Edit: The problem with code now is, that it does only display the default banner on the front page, but it wont’ replace it with a custom div on other pages. So the bottom part of the code doesnt seem to work.

    Thread Starter JaanMatti

    (@jaanmatti)

    Josh – Thanks for the input. For some reason, the code you pasted gives an error:

    Parse error: syntax error, unexpected ‘}’ in /home/kipper/public_html/www.kaaskiri.ee/uus/wp-content/themes/kaaskiri/banner.php on line 17

    Any ideas?

    Oops… Sorry, I haven’t fully tested your code. I only stripped it of unnecessary opening and closing php tags.

    Try this one:

    <?php if (is_front_page()) {
    
        global $options;
        foreach ($options as $value) {
            if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
    
        if ($gear_banner_visibility == "on") { ?>
                        <div class="banner">
                            <div class="paddings">
                                <img src="<?php bloginfo('stylesheet_directory'); ?>/images/ico.big/<?php echo $gear_banner_image; ?>" alt="Gear"></img>
                                <?php echo stripslashes($gear_banner_text); ?>
                            </div>
                            <div class="clear"></div>
                        </div>
    					<?php } } 
    
    else {
    
    echo '<div id="menubottom"></div>';
    
    }
    ?>
    Thread Starter JaanMatti

    (@jaanmatti)

    It works!!!

    Josh, thanks a lot! Just out of curiosity – what was wrong, or what did you change? Would be cool to learn from my mistakes here, hehe.

    Thanks a lot again!

    Great! You’re welcome. Glad to help.

    Well, originally you had about six sets of unnecessary opening and closing php tags. Servers are kind of touchy when having to do this. Look at your original you pasted to pastebin and compare it to the code I provided. You can see the ones I pulled out.

    I didn’t test your code originally, so in the first example I gave you (the one that gave you the error), one of your “if” statements was being closed twice. Hence the unexpected } in the error.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Can't get the if-else conditional tag to work’ is closed to new replies.