Results 1 to 2 of 2

Thread: Is Custom Fields the answer? If so, how?

  1. #1
    jonbey is offline Hello World
    Join Date
    Sep 2010
    Posts
    2

    Default Is Custom Fields the answer? If so, how?

    (I have also posted this question to Wordpress.org, but lack faith in the community there to reply .... )

    I have started adding boxes (an HTML table aligned right) to the top right of some articles which lists hand picked alternative pages.
    I know that I should probably do this with divs and css, but while looking in to that came across another idea - using the custom fields.
    Thing is, I tried custom fields once before but it still displayed some code on the screen even when nothing was in the field.
    OK, maybe I need to show you what I am talking about. See here:http://www.motleyhealth.com/fitness/...e-home-workout
    On the right is a menu "More Workouts". So I am using code like this for that:
    Code:
    <table width="33%" align="right"><tbody><tr><td align="left" valign="top"><h3>More Workouts</h3><ul>    <li> .... links ..... </li></ul></td></tr></tbody></table>
    Which works, but obviously not ideal.
    So, how do I set up a custom field (assuming that this is the best option) which will only show when I add content to that field - and not just show a blank square when there is no content.
    I am going through the articles slowly, there are quite a lot so it is a case of work in progress.

  2. #2
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Use get_post_meta(). Then test for an empty string. e.g.:
    PHP Code:
    $my_meta_value get_post_meta$post->ID'some_meta_key'true );

    if ( 
    '' != $my_meta_value ) {
        
    // Custom field meta key has a value, so 
        // output the table code here

    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

Posting Permissions

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