[Resolved] Output Custom Field in Div Class

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Output Custom Field in Div Class

This topic contains 23 replies, has 3 voices, and was last updated by  Tom 1 month, 3 weeks ago.

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #5488

    Tom
    Keymaster

    You’d have to change the variable:

    $mobile_image = get_field('advertisement_mobile');

    Then do this:

    <div class="mobile-image">
        <?php echo $mobile_image; ?>
    </div>
    
    <div class="desktop-image">
        <?php echo $image; ?>
    </div>
    #5525

    Janek
    Participant

    Holy shit, it works! Your a legend! Thanks for the help! I think I’m slowly grasping the basics of PHP… but don’t think youve seen the last of me! 🙁

    I used the following for anyone who might come after me:

    add_action( 'wpsp_after_title', 'tu_add_advertising_images' );
    function tu_add_advertising_images() {
    if ( function_exists( 'get_field' ) ) {
            $image = get_field('advertisement_desktop');
      $mobile_image = get_field('advertisement_mobile');
    
            if ( ! empty( $image ) ): ?>
    		  
    <div class="desktop-image">		  
    		  <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />   
    </div>
    
    <div class="mobile-image">
        <img src="<?php echo $mobile_image['url']; ?>" alt="<?php echo $mobile_image['alt']; ?>" />
    </div>
      <?php endif;
      
        }
    }
    
    #5544

    Tom
    Keymaster

    Looks good! 🙂

    #9507

    Diana
    Participant

    Hello I have a custom field in some posts (prod1). Is an url link to an image (ej: https://www.iluminet.com/press/wp-content/uploads/2019/01/Konica-mini.jpg). If I use the code:

    add_action( 'wpsp_after_content', 'tu_add_custom_meta' );
    function tu_add_custom_meta() {
        $meta = get_post_meta( get_the_ID(), 'prod1', true );
        if ( isset( $meta ) && '' !== $meta ) {
            echo '<div class="my-class-here">' . $meta . '</div>';
    	
        }
    }

    or use echo esc_url( get_post_meta( get_the_ID(), 'prod1', true ) );

    I just get the text (https://www.iluminet.com/press/wp-content/uploads/2019/01/Konica-mini.jpg) below the title, not the image, I need that as the image. Is it possible?

    Thank you

    Diana

    #9525

    Tom
    Keymaster

    Instead of this:

    echo esc_url( get_post_meta( get_the_ID(), 'prod1', true ) );

    Do this:

    echo '<img src="' . esc_url( get_post_meta( get_the_ID(), 'prod1', true ) ) . '" alt="" />';

    #9548

    Diana
    Participant

    Tom,
    Thank you very much, it works perfect!, just another thing. Is it possible to be clickeable to the post (just like the regular image).

    thanks again for your awesome support.

    Diana

    #9552

    Tom
    Keymaster

    Try this:

    echo '<a href="' . get_permalink( get_the_ID() ) . '"><img src="' . esc_url( get_post_meta( get_the_ID(), 'prod1', true ) ) . '" alt="" /></a>';

    #9556

    Diana
    Participant

    Wow! Works perfect! Thank you very much!

    #9567

    Tom
    Keymaster

    You’re very welcome 🙂

Viewing 9 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic.