• Resolved ttheron

    (@ttheron)


    Hi

    Can someone please help me with some custom coding that I am trying to get working in WP posts.

    <?php if(get_post_meta($post->ID,'is_featured',true) {?>
    <h3><a href="<?php echo get_post_meta($post->ID,'listingweb',true);?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></h3>
    <?php }elseif(get_post_meta($post->ID,'is_featured',false) {?>
    <h3><?php the_title(); ?></h3>
    <?php }?>

    Everything looks fine, but when I upload I get a blank screen.

    Whereas if I remove the else statement is works fine – so what am I doing wrong?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You’re missing a closing bracket on each of your if statements. Try:

    <?php if( get_post_meta( $post->ID, 'is_featured',true ) ) : ?>
    <h3><a href="<?php echo get_post_meta($post->ID,'listingweb',true);?>" title="<?php the_title_attribute(array('before' => '', 'after' => '', 'echo' => 1) ); ?>" target="_blank"><?php the_title(); ?></a></h3>
    <?php elseif  (get_post_meta($post->ID,'is_featured',false) ) : ?>
    <h3><?php the_title(); ?></h3>
    <?php endif;?>
    Thread Starter ttheron

    (@ttheron)

    Hi Esmi,

    Thank you so much – at least now the page is showing. I knew I has missed something simple.

    Can you answer 1 more question for me – why would the title not display if the post is not featured?
    <h3><?php the_title(); ?></h3>
    What am I missing here

    The first line of code above tells WP to ignore the whole code block if the post does not have “featured” custom field.

    Thread Starter ttheron

    (@ttheron)

    shoot – that is not what I wanted – I wanted if the post was featured link the title and if the post is not featured just display the title.

    The php manual from php.net is not very clear on how to do this.

    How do I write this?

    Try:

    <?php if( get_post_meta( $post->ID, 'is_featured',true ) ) : ?>
    <h3><a href="<?php echo get_post_meta($post->ID,'listingweb',true);?>" title="<?php the_title_attribute(array('before' => '', 'after' => '', 'echo' => 1) ); ?>" target="_blank"><?php the_title(); ?></a></h3>
    <?php else : ?>
    <h3><?php the_title(); ?></h3>
    <?php endif;?>

    Thread Starter ttheron

    (@ttheron)

    Oh my!!!

    Thank you, thank you, thank you!!!!

    I have been trying all sorts of coding today. You have saved me!!!

    Finally can go home ??

    Glad I could help ??

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