Support » Themes and Templates » Conditional Custom Field

  • I want to create a conditional statement to populate an image and link based on the custom tags. I’m not exactly a whiz at PHP so I’ve been muddling through it all. Ideally, I’d like to have one custom field called “link-type” with the values of “more” or “programs” which would be used for the conditional statement. I haven’t figured out how to do that and have instead been trying to use two separate custom fields of “programs” and “more” and have them return a value if the value returns true.

    This is what I have so far which doesn’t work:

    <?php if((get_post_meta($post->ID, “programs”, true)) || (get_post_meta($post->ID, “more”, true))) { ?>

    <?php if(get_post_meta($post->ID, "more", true)) ?>
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/btn-content-learnmore.png" alt="" width="110" height="30" /></a>
            <?php if(get_post_meta($post->ID, "programs", true)) ?>
            <a href="<?php echo home_url( '/' ); ?>locations/chesterfield/our-programs/" title="<?php the_title(); ?>"><a href=""<img src="<?php bloginfo('template_directory'); ?>/images/btn-content-viewprograms.png" alt="" width="196" height="30" /></a>
            <?php } ?>

    Any help is GREATLY appreciated.

  • The topic ‘Conditional Custom Field’ is closed to new replies.