• Resolved shaza

    (@shaza)


    What I’m doing is using a custom field (image) and the part number to link to the whole post (like a list).

    The following PHP code works for this, but I’m wondering if there is a way to combine the two meta keys so that it’s easier for the coding purposes (I really am not that good at PHP)

    <?php
    $number= get_post_meta($post->ID, 'Number', true);
    if ( $number ) :
    ?>
    <div class="image">
    <b><?php the_title(); ?> - <?php echo $number; ?></b><br />
    <?php endif; ?>
    
    <?php
    $image = get_post_meta($post->ID, 'url', true);
    if ( $image ) :
    ?>
    <a href="<?php the_permalink(); ?>"><img src="<?php echo $image; ?>" class="img" /></a><br />
    </div>
    <?php endif; ?>

    So I basically want it so that I can put a php code and just have that entire thing in one place.

Viewing 1 replies (of 1 total)
  • Thread Starter shaza

    (@shaza)

    Nevermind, I figured it out

    <?php
    $number= get_post_meta($post->ID, 'Number', true);
    $image = get_post_meta($post->ID, 'url', true);
    if ( $number && $image) {
    ?>
    <div class="image">
    <b><?php the_title(); ?> - <?php echo $number; ?></b><br />
    <a href="<?php the_permalink(); ?>"><img src="<?php echo $image; ?>"
    class="img" /></a><br />
    </div>
    <?php } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Easier PHP for Custom Field’ is closed to new replies.