• Resolved oitavaesfera

    (@oitavaesfera)


    Hi All,
    I’ve searched on this one and can find nothing. Any help would be gratefully appreciated

    I’ve this code to get a image from a custom field

    <?php
    	$values = get_post_custom_values("miniatura");
    	if (isset($values[0])) {
    ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="link permanente para <?php the_title(); ?>"><img src="<?php bloginfo('template_url'); ?>/miniatura/<?php $values = get_post_custom_values("miniatura"); echo $values[0]; ?>" alt="" /></a>
          <?php } ?>

    and this works fine. The post load the image and the css.

    The problem!? How can I make the post print the image and the css only if there is a custom field?

    Can someone help me??

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t know if I understand what you need, but from what I can tell, the piece of code you wrote above will ouput nothing when the custom field is empty…

    No?

    The “if” condition if (isset($values[0])) make the link and the img tag appear only if there is something in $value… If no, it does nothing…

    S.

    Thread Starter oitavaesfera

    (@oitavaesfera)

    True indeed.
    The problem it’s that on a post without the custom field the css still gets printed making appear a blank space on the posts.

    Maybe its not a problem after all and only a bad css coding.

    Well, put the your css in your code… ??

    Then, it will relative to the condition just like the img tag

    <?php
    	$values = get_post_custom_values("miniatura");
    	if (isset($values[0])) {
    ?>
    -------> <div class for your image>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="link permanente para <?php the_title(); ?>"><img src="<?php bloginfo('template_url'); ?>/miniatura/<?php $values = get_post_custom_values("miniatura"); echo $values[0]; ?>" alt="" /></a>
    -------> </div class for your image>
          <?php } ?>

    S.

    By the way, there is a mistake in your link above… I can’t open oitavaesfera[dot]com

    S.

    Thread Starter oitavaesfera

    (@oitavaesfera)

    Solved.
    Thanks for all the feedback and support.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if custom field then print else don’t print’ is closed to new replies.