www.webdeveloper.com
Results 1 to 2 of 2

Thread: Make table disappear when fields are blank? (wordpress)

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Posts
    1

    Make table disappear when fields are blank? (wordpress)

    So I made a simple table out custom meta box fields. What I would like to know is, how can I make the table disappear if the fields aren't filled in?

    I'd like the table to disappear if at one field is not filled in.

    Code:
    <div>
    <table class="animetable">
    <tr><th>Info</th></tr>
    <tr><td><strong>Name: </strong><?php echo get_post_meta($post->ID, 'anime_anname', true); ?></td></tr>
    <tr><td><strong>Genre: </strong><?php echo get_post_meta($post->ID, 'anime_angenre', true); ?></td></tr>
    <tr><td><strong>Directed by: </strong><?php echo get_post_meta($post->ID, 'anime_andirector', true); ?></td></tr>
    <tr><td><strong>Music by: </strong><?php echo get_post_meta($post->ID, 'anime_anmusic', true); ?></td></tr>
    <tr><td><strong>Studio: </strong><?php echo get_post_meta($post->ID, 'anime_anstudio', true); ?></td></tr>
    <tr><td><strong>Licensed ny: </strong><?php echo get_post_meta($post->ID, 'anime_anlicense', true); ?></td></tr>
    <tr><td><strong>Network[s]: </strong><?php echo get_post_meta($post->ID, 'anime_annetwork', true); ?></td></tr>
    <tr><td><strong>Original run: </strong><?php echo get_post_meta($post->ID, 'anime_anrun', true); ?></td></tr>
    <tr><td><strong>Episodes: </strong><?php echo get_post_meta($post->ID, 'anime_anepisodes', true); ?></td></tr>
    </table>
    </div>

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    gross, what is all that obscure undocumented functionality you're using.

    There are some fancier mathematical ways to do it (naming each field after a unique prime number and checking that the multiple of all post values is the product of all unique primes, this has some other interesting properties that are very desirable). But, an equally as acceptable/correct and more standard way of doing it is this:

    PHP Code:
    <?php

    $expectedPostKeysArray 
    = array('foo','bar','baz');
    while(
    array_key_exists(end($expectedPostKeysArray),$_POST))
      
    array_pop($expectedPostKeysArray);

    echo empty(
    $expectedPostKeysArray) ?
      
    "Yes, all the keys i was expecting showed up" :
      
    "No, some of the keys were missing.";
    Edit:
    Can anyone find a way to do it in constant time?
    Last edited by eval(BadCode); 08-22-2012 at 05:09 AM.
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles