Forums

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

  1. deeltje
    Member
    Posted 6 months 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 6 months 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 6 months 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 1 week 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 1 week 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??

Reply

You must log in to post.

About this Topic