Support » Fixing WordPress » Echo something if something else is there…

  • joeybottle

    (@joeybottle)


    Hello everybody! I have this piece of code in my query:

    [please mark your code using the code button or backticks]

    <?php $image3 = get_post_meta($post->ID, "Image3", true); echo $image3; ?>

    And I want to have on another place a code which checks if there acutally IS an Image3…If I added the custom-field Image3 in that post. If not nothing should be echoed…but IF there is an Image3 than on that place should be
    <a href="#"></a>
    echoed!!!!!

    Please help me! Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • well…your code isn’t totally there, but I think I get it…

    <?php if( get_post_meta($post->ID, "Image3", true) ): ?>
    <?php echo get_post_meta($post->ID, "Image3", true): ?>
    <?php else : ?>
    code to display if no image
    <?php endif; ?>

    that’s the basic code. You can swap out the second line for whatever you want to show if IMage3 exists, and you can fill in line 4 with whatever to show if nothing exists….

    Thread Starter joeybottle

    (@joeybottle)

    Oke I understand this one but I have a bigger problem I think! That is my whole code where this question belongs to:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
    		<h2><?php the_title(); ?></h2><?php $subtitle = get_post_meta($post->ID, "Subtitle", true); echo $subtitle; ?>
    
    		<div class="entry">
    
    		<!-- container for the slides -->
    		<div class="images">
    
    			<div><?php $image1 = get_post_meta($post->ID, "Image1", true); echo $image2; ?></div>
    			<div><?php $image2 = get_post_meta($post->ID, "Image2", true); echo $image2; ?></div>
    			<div><?php $image3 = get_post_meta($post->ID, "Image3", true); echo $image3; ?></div>
    			<div><?php $image4 = get_post_meta($post->ID, "Image4", true); echo $image4; ?></div>
    			<div><?php $image5 = get_post_meta($post->ID, "Image5", true); echo $image5; ?></div>
    			<div><?php $image6 = get_post_meta($post->ID, "Image6", true); echo $image6; ?></div>
    
    		</div><!-- slider ENDE -->		
    
    		<div id="frontcover_controller">
    	<!-- "previous slide" button -->
    	<a>prv</a>
    
    	<!-- "next slide" button -->
    	<a>nxt</a>
    
    <div class="slidetabs">
    
    		<a href="#"></a>
    		<a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
    
    	</div>
    	</div><!-- frontcover_controller ENDE -->
    
    	<script type="text/javascript">
    	// What is $(document).ready ? See: http://flowplayer.org/tools/documentation/basics.html#document_ready
    	$(function() {
    
    	$(".slidetabs").tabs(".images > div", {
    
    		// enable "cross-fading" effect
    		effect: 'fade',
    		fadeOutSpeed: "slow",
    
    		// start from the beginning after the last tab
    		rotate: true
    
    	// use the slideshow plugin. It accepts its own configuration
    	}).slideshow({autoplay: true, autopause: true, clickable: false, interval: 10000});
    	});
    	</script>

    So as you can see there are acutally 6 times the “Image”-Thing and for those are also exactly 6 times the “” there. If I do NOT Fill in some of the Image1-Image6 Fields in my posts it just doesnt show them, that’s oke! But the way it is now I still have 6 times the ““. But It should just be there as often as I fill in Image1-Image6 Fields in my Post…

    Hope you understand me now better…How can I manage to do this???

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Echo something if something else is there…’ is closed to new replies.