Grow your CSS skills. Land your dream job.

Default image in custom field

  • Rai
    # July 20, 2011 at 4:44 pm

    Hello guys,

    I´m looking for a solution to have a default image when this custom field (wordpress) it is not in use.

    	 '/>

    Any idea?
    Many thanks.
    Rai.

    # July 20, 2011 at 4:50 pm
    < ?php
    $img = get_post_meta($post->ID, 'imagen', true);

    if ($img) {
    echo '';
    } else {
    echo '';
    }
    ?>
    Rai
    # July 20, 2011 at 5:49 pm

    Thanks Doc,

    But it show me this error:

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/57/6689957/html/azahararomaterapia/wp-content/themes/azahar/pagina-producto.php on line 19
    # July 20, 2011 at 7:00 pm

    Oops! Terrible copy/pasting!

    < ?php
    $img = get_post_meta($post->ID, 'imagen', true);

    if ($img) {
    echo '';
    } else {
    echo '';
    }
    ?>

    Give that a go!

    Rai
    # July 20, 2011 at 7:21 pm

    Excellent Doc!,

    Can you recommend something to read to learn the code at that level?.

    Thanks.

    # July 20, 2011 at 7:43 pm

    That was actually just a modified version of a snippet from this very site! http://css-tricks.com/snippets/wordpress/using-custom-fields/

    As far as suggestions on where to learn, I don’t really have any. It’s just repetition, practice practice practice.

    Try to not take on too much at once or else none of it will stick. Focus on a few features at a time and really try to master them before you move on to something else.

    Rai
    # July 21, 2011 at 5:02 pm

    Thanks Doc!.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".