Forums

[resolved] [hack: custom field template] Show title of a custom field only if exists (3 posts)

  1. carlosgonca
    Member
    Posted 6 months ago #

    I think It´s not a hack but I need to change this code to conditional but I don´t know how.

    I need that if this custom type content doesn´t exist, the title and space to it doesn´t show in site. How can I do this?

    <a href="<?php
    $download = get_post_meta($post->ID, 'brochura-pdf', true);
    echo wp_get_attachment_url($download);
    ?>" target="_blank">Brochura</a></br>
    <?php  $video = get_post_meta($post -> ID, 'video Youtube',true) ?>
    					<?php  echo $video; ?>

    I tried with this but I get error message:

    <?php if $download = get_post_meta($post->ID, 'manual em pdf', true) {?>
    <a href="<?php
    $download = get_post_meta($post->ID, 'manual em pdf', true);
    echo wp_get_attachment_url($download);
    ?>" target="_blank">Manual</a></br>
    <?php } else {?>
    nothing
    <?php }?>
  2. esmi
    Theme Diva & Forum Moderator
    Posted 6 months ago #

    Try:

    <?php $download = get_post_meta($post->ID, 'manual em pdf', true);
    if( $download ) :?>
    <a href="<?php echo wp_get_attachment_url($download);?>" target="_blank">anual</a></br>
    <?php endif;?>
  3. carlosgonca
    Member
    Posted 6 months ago #

    Perfect! Thanks a lot for your help!

Reply

You must log in to post.

About this Topic