WordPress.org

Ready to get started?Download WordPress

Forums

[displaying standard image]Custom field image, if no image excists (7 posts)

  1. deeltje
    Member
    Posted 5 years ago #

    (using 2.7.1 on PHP5)

    Hi there,

    I'm using a customfield option to display my images on my website:

    <img src="<?php echo get_nkm_imageurl('customfoto'); ?>" width="320px" height="240px" alt="fotolinks" />

    As you can see I'm using the NKMImageField plugin, but that shouldn't matter as it is using customfields (as far as I know).

    The problem is that this plugin is still far from perfect, when you are changing a topic in it's status (published etc.) it loses this fields information and no image is being displayed (because the img =src"" has nog source-information anymore).

    Does anyone here know a way to change this? I kinda need some sort of code to tell the img src="" that, when it's empty, it needs to use a standard image (images/noimage.jpg). Could someone help me with this?

  2. deeltje
    Member
    Posted 5 years ago #

    I figured it out myself (pfff not easy without any php knowledge)

    Code was:

    <?php echo get_nkm_imageurl('customfoto'); ?>

    Code now is:

    <?php
    $emptyvar = 'http://www.url.ext/client/wp-content/themes/theme/images/nophoto.jpg';
    $var = get_nkm_imageurl('customfoto');
    if ($var == '')
    {
    echo $emptyvar;
    } else {
    echo $var;
    } ?>

    All I need to do now is implement

    <?php bloginfo('template_url'); ?>

    into the emptyvar, no idea how to do that yet...

  3. taghaboy
    Member
    Posted 5 years ago #

    The NKMImageField plugin is a perfect and free plugin for custom field images ever made.
    Try this code (i did not test it yet)

    <?php
    $emptyvar = 'http://www.url.ext/client/wp-content/themes/theme/images/nophoto.jpg';
    $var = get_nkm_imageurl('customfoto');
    if ($var == '')
    {
    echo $emptyvar;
    } else {
    echo 'bloginfo("template_url");/$var"/>';
    } ?>

    and try also this code, with it you can add any php or HTML tags:

    <?php $values = get_nkm_imageurl('customfoto'); // set the img custom name
    if (isset($values[0])) { // if there's a img in my custom field
    	?>
    		<img src="<?php $values = get_post_custom_values("image"); echo $values[0]; ?>" title="<?php the_title(); ?>"/>
    	<?php } // end if statement
    			// if there's no img do replace it with noimage.jpg
    	else { ?>
    		<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" title="<?php the_title(); ?>"/>
    	<?php } ?>

    That's all.

  4. marujobhz
    Member
    Posted 4 years ago #

    hi. im using kimili in a site, to embed flashmovies in some pages. i made a custom field to insert it in the posts:

    <?php get_post_meta($post->ID, 'flash-wide', false); ?>
    <img src="<?php echo get_post_meta($post->ID, 'flash-wide', true); ?>" />
    so, i add this customfield 'flash-wide' and as a value, i put the kml param. in FF its ok. but in IE, the flash doesnt appear. there is a box with red x in the place. can you help me? thanks.
    im using this param:
    [kml_flashembed movie="http://yourdomain.com/path/to/slideshowpro.swf" height="400" width="600" base="." /]

    and i use a customfield for image too. and, i f i not insert the customfiled, in IE appears the same box with red X. i hate IE!!

  5. marujobhz
    Member
    Posted 4 years ago #

    i describe!! i exclude the parts "<img src=" and "" />". the ok is:
    <?php echo get_post_meta($post->ID, 'flash-wide', true); ?>
    but, if i dont insert a image in the custom field (imagewide) in IE the box with red x appears. any idea??

  6. ddpweb
    Member
    Posted 4 years ago #

    Thanks taghaboy for the code. But I have not been able to get either of your examples to work. I'm sure it's really close.

  7. nmillman
    Member
    Posted 4 years ago #

    taghaboy's code should work the same way in 0.6 as it did in earlier versions. (A lot of the bugs in the plugin have been fixed in v0.6 -- I recommend all users upgrade).

    ddpweb, could you please post the exact code you're using and the output you're getting?

Topic Closed

This topic has been closed to new replies.

About this Topic