Forums

[resolved] Conditional Display of Content with Custom Fields (3 posts)

  1. SteveP
    Member
    Posted 2 years ago #

    Hi,

    I know it's a bit cheeky asking for help with a first post, but I searched and couldn't find an answer to me problem.

    Basically, in single.php I am grabbing a couple of custom fields by the names of 'demo' and 'download', it is being done thusly:

    <table border="0" cellspacing="0" cellpadding="5" class="downAlign">
     						 <tr>
        						<td><a href="<?php echo get_post_meta( $post->ID, "demo", true ); ?>" title="Demo"><img src="<?php bloginfo( 'template_directory' ); ?>/images/demo.png" class="none" alt="Demo" /></a></td>
        						<td align="left">&nbsp;&nbsp;<a href="<?php echo get_post_meta( $post->ID, "demo", true ); ?>" class="postDeets" title="Demo">Demo</a><br />&nbsp;&nbsp;<span class="underDeet">See our demo</span></td>
        						<td><a href="<?php echo get_post_meta( $post->ID, "download", true ); ?>" title="Download"><img src="<?php bloginfo( 'template_directory' ); ?>/images/download.png" class="none" alt="Demo" /></a></td>
        						<td align="left">&nbsp;&nbsp;<a href="<?php echo get_post_meta( $post->ID, "download", true ); ?>" class="postDeets" title="Download">Download</a><br />&nbsp;&nbsp;<span class="underDeet">Get the source</span></td>
      						</tr>
    					</table>

    Simple enough. And I know... tables... ugghh... not my choice I can assure you.

    What I would like is that if those custom fields are not in use at all, then the whole table they are contained within does not show at all.

    I cam across this thread

    http://wordpress.org/support/topic/204270?replies=6

    But it was for displaying the custom field only, and not the surrounding elements too.

    Could someone help me out?

  2. SteveP
    Member
    Posted 2 years ago #

    Nevermind, worked it out myself. Sorry for the fuss :P

    If your interested how:

    <?php
    $demo = get_post_meta($post->ID, 'demo', true);
    if ($demo == '')
    { ?>
    
    <?php } else { ?>
    
                        <div class="containerX"><table border="0" cellspacing="0" cellpadding="5" class="downAlign">
     						 <tr>
        						<td><a href="<?php echo get_post_meta( $post->ID, "demo", true ); ?>" title="Demo"><img src="<?php bloginfo( 'template_directory' ); ?>/images/demo.png" class="none" alt="Demo" /></a></td>
        						<td align="left">&nbsp;&nbsp;<a href="<?php echo get_post_meta( $post->ID, "demo", true ); ?>" class="postDeets" title="Demo">Demo</a><br />&nbsp;&nbsp;<span class="underDeet">See our demo</span></td>
        						<td><a href="<?php echo get_post_meta( $post->ID, "download", true ); ?>" title="Download"><img src="<?php bloginfo( 'template_directory' ); ?>/images/download.png" class="none" alt="Demo" /></a></td>
        						<td align="left">&nbsp;&nbsp;<a href="<?php echo get_post_meta( $post->ID, "download", true ); ?>" class="postDeets" title="Download">Download</a><br />&nbsp;&nbsp;<span class="underDeet">Get the source</span></td>
      						</tr>
    					</table></div>
    <?php } ?>
  3. Adam
    Member
    Posted 2 years ago #

    Great! Thanks! This worked perfect for me.

Topic Closed

This topic has been closed to new replies.

About this Topic