• Resolved myriadp

    (@myriadp)


    Hi,
    would really appreciate if any PHP experts out there could help me?

    Could you tell me why the following code is not working, in my single.php:

    [code moderated per forum rules - please follow the guidelines http://codex.wordpress.org/Forum_Welcome#Posting_Code for posting code]

    I am getting the error message:
    Parse error: syntax error, unexpected '<' in site/single.php on line 44
    Line 44 is the third line in the code shown.

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • As the code has been removed, can you add it to http://pastebin.com and post the link back in a reply.

    It looks like you have an unclosed <?php ; ?> statement, check the code before line 44 and look for any missing braces } or php end tags ?>

    An example that would error would be:

    <?php get_header();
    	<div id="container">

    The closing tag ?> is missing (close php and open html), should be:

    <?php get_header(); ?>
    	<div id="container">

    Else if:

    <?php if($condition==1) : ?>
       <h2 class="entry-title">Blah Blah<h2>
    <?php elseif($condition==2) : ?>
       <h1 class="entry-title">Blah Blah<h1>
    <?php else : ?>
       <h3 class="entry-title">Blah Blah<h3>
    <?php endif; ?>

    HTH

    David

    Thread Starter myriadp

    (@myriadp)

    Whoops!
    http://pastebin.com/TqwswuD0

    Thanks for the reply – much appreciated.
    I think it must be this code as the page works fine without it?

    You have mixed code php and html you need to break the php code.

    Solution.

    <?php if( in_category('sponsored-posts') ) { ?>
    
    <?php } elseif( in_category('guest-posts') ) { ?>
    
    <?php } else { ?>
    
    <?php } ?>

    Or UNTESTED updated code using : ; and not {}.
    http://pastebin.com/Sp4BECHZ

    HTH

    David

    Thread Starter myriadp

    (@myriadp)

    Thank you Ever so much for your help – worked perfectly.
    Just 1 final question!
    In the sponsored-posts category, I don’t want any code (I don’t want anything to display) so can I just leave it blank or should I add {} which I have seen in other examples?

    Just leave it blank, also could you mark this as resolved please.

    David

    Thread Starter myriadp

    (@myriadp)

    Thanks again…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Help with Elseif’ is closed to new replies.