WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Field Template not calling images in PHP (5 posts)

  1. bluecedardesign
    Member
    Posted 4 years ago #

    Obviously I'm doing something wrong here, but can't figure out the solution. I'm attempting to use CFT in a CMS for a portfolio site, calling thumbnail images that link to the full portfolio image in lightbox. Here's the code I have:

    <?php if(get_post_meta($post->ID, "portfolio_image", true)) { ?>
    
    <a href="<?php echo get_post_meta($post->ID, "portfolio_image", true); ?>" rel="lightbox[<?php the_ID(); ?>]">
    <img src="<?php if(get_post_meta($post->ID, "portfolio_thumbnail", true)) { ?><?php echo get_post_meta($post->ID, "portfolio_thumbnail", true); ?><?php } ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>">
    </a>
    
    <?php } ?>

    Instead of getting an image, I'm only getting the alt for the link and the lightbox just spins. I know that the images have been uploaded through CFT, so they're definitely there, but I also realize I'm not calling them up correctly.

    Would appreciate any help I could get.

    http://wordpress.org/extend/plugins/custom-field-template/

  2. bluecedardesign
    Member
    Posted 4 years ago #

    Also, this is what I have for my template options:

    [portfolio_image]
    type = file
    relation = true

    [portfolio_thumbnail]
    type = file
    relation = true

  3. bluecedardesign
    Member
    Posted 4 years ago #

    So after further research, I found out that for some reason CFT is assigning a number value to the images I'm uploading, rather than using the URL as a value.

    How do I make sure that the value assigned to each image is the URL rather than a number?

  4. bluecedardesign
    Member
    Posted 4 years ago #

    Figured out my own problem. Had to use wp_get_attachment_url:

    <?php if(get_post_meta($post->ID, "portfolio_image", true)) { ?>
    
                                    <a href="<?php $portfolio_image = get_post_meta($post->ID, 'portfolio_image', true);
    echo wp_get_attachment_url($portfolio_image); ?>" rel="lightbox[<?php the_ID(); ?>]"><img src="<?php $portfolio_thumbnail = get_post_meta($post->ID, 'portfolio_thumbnail', true);
    echo wp_get_attachment_url($portfolio_thumbnail); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"></a>
    
                                    <?php } ?>

    Took all day, but I hope this may help someone else!

  5. svedish
    Member
    Posted 4 years ago #

    Such a good habit to post solutions we find alone. Thanks for sharing. :)

Topic Closed

This topic has been closed to new replies.

About this Topic