WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] if is in a category show this else dysplay other (8 posts)

  1. radiocono
    Member
    Posted 1 year ago #

    I have a problem with this loop. I think it's not closed on the line number 13
    one of you knows how to close it properly?

    <?php if ( in_category('CATEGORY NAME') ) {
    echo"HTML CODE";{ ?>
    <?php if (get_post_meta($post->ID, 'KEY', true) ) { ?>
    
    <!-- html code -->
    
    <?php } else { ?>
    
    <!-- html code -->
    
    <?php }     
    
    elseif ( in_category('CATEGORY NAME 2') ) {
    
    } else {
    
    }
    ?>
  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    What is the error you're getting and which line is it referring to?

  3. Evan Herman
    Member
    Posted 1 year ago #

    I believe this is it -

    <?php if ( in_category('CATEGORY NAME') ) {
    echo"HTML CODE";{ <---- notice you are opening another curly bracket, before closing the previous one ?>
    <?php if (get_post_meta($post->ID, 'KEY', true) ) { ?>

    Correct variation might be

    <?php if ( in_category('CATEGORY NAME') ) { ?>
    <?php echo"HTML CODE"; ?>
    <?php } elseif (get_post_meta($post->ID, 'KEY', true) ) { ?>
    
    <!-- html code -->
    
    <?php } elseif (some conditional) { ?>
    
    <!-- html code -->
    
    <?php } elseif ( in_category('CATEGORY NAME 2') ) {    
    
    <!-- html code -->
    
    } else {
    <!-- html code -->
    }
    ?>
  4. radiocono
    Member
    Posted 1 year ago #

    on the editor tex code it said line 13 error
    where the code says:
    elseif ( in_category('CATEGORY NAME 2') ) {

    } else {

    }
    ?>

  5. radiocono
    Member
    Posted 1 year ago #

    now i try the loop by Evan Herman

  6. radiocono
    Member
    Posted 1 year ago #

    what is necessary to add in (some conditional)?
    maybe
    (get_post_meta($post->ID, 'KEY', true) )

  7. radiocono
    Member
    Posted 1 year ago #

    sorry
    (get_post_meta($post->ID, 'KEY', false) )

  8. radiocono
    Member
    Posted 1 year ago #

    Evan Herman
    thank you very much

Topic Closed

This topic has been closed to new replies.

About this Topic