Forums

[resolved] Help with Elseif (7 posts)

  1. myriadp
    Member
    Posted 9 months ago #

    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

  2. Digital Raindrops
    Member
    Posted 9 months ago #

    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

  3. myriadp
    Member
    Posted 9 months ago #

    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?

  4. Digital Raindrops
    Member
    Posted 9 months ago #

    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

  5. myriadp
    Member
    Posted 9 months ago #

    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?

  6. Digital Raindrops
    Member
    Posted 9 months ago #

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

    David

  7. myriadp
    Member
    Posted 9 months ago #

    Thanks again...

Reply

You must log in to post.

About this Topic

Tags