Support » Fixing WordPress » php if statement makes whole screen go blank

  • Resolved Scientific Living

    (@scientific-living)


    My site is healingresearch.net. I am editing single.php. The following code displays the purple banner on my articles:

    <?php
    $link = ‘http://healingresearch.net/get-paid-to-use-unlimited-4g-mobile-service/’; // url link
    $src = ‘http://healingresearch.net/wp-content/uploads/2012/09/solavei-banner-4.jpg’; // image url
    echo ‘<img style=”border:none;” src=”‘. $src .'” />‘;
    ?>

    What I want to change is that the banner does not display on a particular post that happens to be number 4073. So that echo statement I want to put a condition around it. But every time I put an if statement, the whole screen goes blank. Can anyone offer a code I should attempt?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you please post the code you are trying to use?

    Try WordPress conditional tag as follows:

    if(!is_page($post->ID)){
     echo '<img src="'. $src .'" alt="" style="border:none;" />';
    }

    Where $post->Id is denotes the post that you want to exclude from showing image (e.g. ‘4073’) and please remove ‘image url’ that you have written just above your echo code.

    For More Reference: http://codex.wordpress.org/Conditional_Tags

    Thanks. Well, at least I can now get an if statement that does not make the screen turn blank. For example, the following article still appears:

    http://healingresearch.net/2012/09/find-an-integrative-practitioner-md-nd-nurse-dentist-all-illnesses-cancer-lyme-disease/

    When I have the code:

    <?php
    the_ID();
    $link = 'http://healingresearch.net/get-paid-to-use-unlimited-4g-mobile-service/'; // url link
    $src = 'http://healingresearch.net/wp-content/uploads/2012/09/solavei-banner-4.jpg'; // image url
    if(!is_page(3970)){
     echo '<img src="'. $src .'" alt="" style="border:none;" />';
    }
    ?>

    If don’t know how this was different than other things I tried, but anyway, I’m glad something is displaying.

    You can see that I put a print statement just to verify this post has the ID of 3970. I would expect then that on this particular post, the if statement would make sure that image is not displayed. Unfortunately, it is still displaying. Any ideas?

    Also, I guess a moderator removed part of the echo statement that used the $link variable to actually make the image link to the page I wanted. Can someone show me how to add that back into the echo statement? It took me longer to figure that out the first time that I would like to admit.

    Here is the code of my entire single.php:

    <?php get_header(); ?>
    
    <div id="wrapper">
    	<div id="content">
    
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<b>
    		<div class="navigation">
    			<div class="alignleft">Older <?php previous_post_link('&laquo; %link') ?></div>
    			<br>
    			<div class="alignleft">Newer <?php next_post_link('&raquo; %link ') ?></div>
    				<div style="clear:both;"></div>		</div>	</b>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    
    <?php
    the_ID();
    $link = 'http://healingresearch.net/get-paid-to-use-unlimited-4g-mobile-service/'; // url link
    $src = 'http://healingresearch.net/wp-content/uploads/2012/09/solavei-banner-4.jpg'; // image url
    if(!is_page(3970)){
     echo '<img src="'. $src .'" alt="" style="border:none;" />';
    }
    ?>
    
    			<h2><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    			<?php //include('adsense_singlepost_top_banner.php') ?>
    
    			<div class="entrytext">
    
    				<?php include('adsense_singlepost_top_square.php') ?>
    
    				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    
    				<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    
    				<div style="clear:both;"></div>
    
    <br><br>
    		<b><font size=1>
    		<div class="navigation">
    			<div class="alignleft">Older <?php previous_post_link('&laquo; %link') ?></div>
    			<br>
    			<div class="alignleft">Newer <?php next_post_link('&raquo; %link ') ?></div>
    			<div style="clear:both;"></div>	</div>	</font>	</b>
    
    				<div>
    				<p class="postmetadata alt">
    					<small>
    						This entry was posted
    
    						on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?>.
    
    						<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    							// Both Comments and Pings are open ?>
    
    						<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    							// Only Pings are Open ?>
    							Responses are currently closed, but you can <a href="<?php trackback_url(true); ?> " rel="trackback">trackback</a> from your own site.
    
    						<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    							// Comments are open, Pings are not ?>
    							You can skip to the end and leave a response. Pinging is currently not allowed.
    
    						<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    							// Neither Comments, nor Pings are open ?>
    							Both comments and pings are currently closed.			
    
    						<?php } edit_post_link('Edit this entry.','',''); ?>
    					</small>
    				</p>
    				</div>
    			</div>
    		</div>
    	<?php include('adsense_singlepost_bottom_square.php') ?>
    	<?php //include('adsense_singlepost_bottom_banner.php') ?>
    	<?php comments_template(); ?>
    	<?php endwhile; else: ?>
    		<p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
    	</div>
    <?php get_sidebar(); ?>
    </div>
    <?php get_footer(); ?>

    Thanks!
    David

    Holy cow…thanks for that link to the conditional tags reference. The function is_single ( ‘3970’) did the trick!

    Ok got it. Thanks!

    I need solavei certified templates for my site?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘php if statement makes whole screen go blank’ is closed to new replies.