• Resolved LearnWebCode

    (@learnwebcode)


    Hi everyone,

    I’m trying to have a bit of custom text (from a custom field) display, and if a page doesn’t have that custom field, than have a default/standby bit of text appear. Here is the code I’m using, and I’m receiving a “unexpected T_ENDIF” syntax error. I’m a true beginner in PHP, so if it’s something obviously wrong (which I’m sure it is), please be kind 🙂

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php $pageHeader=get_post_meta($post->ID, 'pageHeader', true); ?>
        <?php if ( $pageHeader ) { ?>
    
        <!-- with custom page header -->
    	<?php echo $pageHeader; ?>
        <?php } else { ?>
    
        <!-- without custom page header -->
    	Sample code
        <?php endif; ?>
    
          <?php
    			if ( has_post_thumbnail() ) {
    			the_post_thumbnail();
    			}
    			?> 
    
    			<h1><?php the_title(); ?></h1>
    			<?php the_content(); ?>
    
    		<?php endwhile; endif; ?>

    Any ideas? Any help is greatly appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter LearnWebCode

    (@learnwebcode)

    I discovered the problem.

    In case any other PHP beginners have the same question/problem, here’s the fix.

    The <?php endif; ?> after the “without custom page header” section should be removed, and in its place, add:

    <?php } ?>

Viewing 1 replies (of 1 total)

The topic ‘Syntax Error in Conditional Custom Field Code’ is closed to new replies.