• Hey guys,

    Is there a way, after adding a Custom Field to a post, to then put the content of that Custom Field in to content.php to show on the Category page?

    I’d basically like to be able to make a Custom Field with:

    Name: RoR
    Value: /wp-includes/images/ror35.png

    Then be able to display that Value inside an img tag within the category archive page, by adding it to content.php

    An example, on this link below, next to “June 27th, 2014 by Rock On” I’d like to be able to put an image that’s dragged in from the Custom Field for that post.

    http://rockonpublishing.co.uk/unsigned-reviews/

    I’ve had a good old look through Google but can’t find what I need to do.

    Any ideas? I’m using Twenty Thirteen theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try this where you want to display the custom field.

    <?php
        $img = get_post_meta( get_the_ID(), 'RoR', true);
        if( ! empty( $img ) ) {
            echo '<img src="' . $img . '" />';
        }
    ?>

    Haven’t tested it, but it should work. Let me know.

    Thread Starter roptech

    (@roptech)

    Absolutely brilliant, thanks!

    Thread Starter roptech

    (@roptech)

    Is it possible to put in place an if statement that says if there is a custom field with the name of RoR, then show X?

    Like:

    IF {custom field name} exists

    {content here}

    ENDIF

    Thread Starter roptech

    (@roptech)

    Any clue, anyone?

    Thread Starter roptech

    (@roptech)

    I actually managed to figure it out myself from trial/error/looking at other working code.

    For anyone interested:

    <?php
    $key = 'SCurl';
    $themeta = get_post_meta($post->ID, $key, TRUE);
    ?>
    <?php if($themeta != '') : ?>
    <div class="entry-single-info">
    	<span><strong>Soundcloud:</strong> <a href="http://soundcloud.com<?php $scurl = get_post_meta( get_the_ID(), 'SCurl', true); if( ! empty( $scurl ) ) { echo '' . $scurl . ''; } ?>" target="_blank"><?php $scurl = get_post_meta( get_the_ID(), 'SCurl', true); if( ! empty( $scurl ) ) { echo '' . $scurl . ''; } ?></a></span>
    </div>
    
    <?php else : ?>
    
    <?php endif; ?>

    This shows, e.g. “Soundcloud: /soundcloudlink (<< that being a link to the soundcloud) if the custom field named SCurl exists and has data. There is probably a cleaner way to do this, but it works for me 🙂

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

The topic ‘Adding post Custom Field to content.php’ is closed to new replies.