• thesingleparentperspective

    (@thesingleparentperspective)


    Please forgive my ignorance up front. I am a newbie with coding.

    I am using this code in my header to display an image that is listed in the post custom field

    <?php
        $img = get_post_meta($post->ID, 'header-image', true);
      	if ($img) {
    	    echo "<img src='$img' />";
    	}
    	else {
    		echo "<img src='http://ictlive00.com/wp-content/uploads/Wichitanightskyline1220x250.jpg' />";
    	}
    ?>

    It works except on home and category and such.
    For regular pages it is displaying the else statement and for post pages it is displaying the image in the custom field.

    What do I need to add to display the else statement on home, category and archive pages?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter thesingleparentperspective

    (@thesingleparentperspective)

    Oh Alleluia

    I love it when I find my own solutions!

    <?php
        $img = get_post_meta($post->ID, 'header-image', $single = true);
      	if(is_single() ){
    	    echo "<img src='$img' />";
    	}
    	else {
    		echo "<img src='http://ictlive00.com/wp-content/uploads/Wichitanightskyline1220x250.jpg' />";
    	}
    ?>

    Works

    Edit:

    I spoke too soon.

    I am using events manager and on the single event page it is not displaying anything in the header
    http://ictlive00.com/events/test-event/

    Thread Starter thesingleparentperspective

    (@thesingleparentperspective)

    Thread Starter thesingleparentperspective

    (@thesingleparentperspective)

    Ok, it took some doing but finally got it to work.

    <?php
        $img = get_post_meta($post->ID, 'header-image', $single = true);
    
      	if ($img){
    	    echo "<img src='$img' />";
    	}
    
    	else {
    		echo "<img src='http://ictlive00.com/wp-content/uploads/Wichitanightskyline1220x250.jpg' />";
    	}
    
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘using custom field in header’ is closed to new replies.