• Caveat: I’m not a programmer! : )

    Ok, so, through much searching I’ve put this function below together to create a shortcode so that my client can specify which posts she wants on the homepage. So all she has to do when she wants a particular number of posts on the homepage is put this [featured post=322]. Here is the code I used:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Now sometimes there is a credit for a photographer that will go under the author byline. So I found this bit of code below for a custom field that will only show if this custom field is used. If I don’t use this custom field nothing appears in the post or archive pages, which is good. Here is this code:

    <?php if( get_post_meta($post->ID, "photographer", true) ): ?>
    	Photos by <a href="<?php echo get_post_meta($post->ID, "photographer_link", true); ?>"><?php echo get_post_meta($post->ID, "photographer", true); ?></a>
    <?php endif; ?>

    What I need help with is how do I get that photographer custom field code into the featured post function underneath where the author byline is? I can add this in

    $return .= '<div id="featured-wide-author">Photos by <a href="'.get_post_meta($post->ID, "photographer_link", true).'">' .get_post_meta($post->ID, "photographer", true). '</a></div><br />';

    which works but of course the “Photos by” will always be showing whether or not I use the custom field. Basically I need the if/endif part to be in there.

    I hope this makes sense and I hope someone can help me with this. Is this even possible?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Your code was moderated, use wordpress.pastebin.com

    Thread Starter dangle2k

    (@dangle2k)

    Ok, here is the link to the code in pastebin.com

    http://pastebin.com/ckf3gW7j

    Still looking for help on this!

    thanks again.

    You can still wrap it in the same conditional statement, something like:

    if( get_post_meta( $post->ID, 'photographer', true ) ) {
        $return .= '<div id="featured-wide-author">Photos by <a href="'.get_post_meta($post->ID, "photographer_link", true).'">' .get_post_meta($post->ID, "photographer", true). '</a></div><br />';
    }

    HTH

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Trying to include a custom field code into a function’ is closed to new replies.