Display Conditional Content in WordPress Template

Alright, so I have this block of code in my current theme:

<div class="content_block">

                <?php the_content(); ?>

                <div class="<?php echo $left_block; ?>">

                    <?php  $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
                        if ( $project_photos ) : ?>
                                <div class="grid_gallery clearfix">
                                    <?php foreach( $project_photos as $project_photo ) { ?>
                                        <figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
                                            <a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto">
                                                <img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
                                            <span class="zoom-icon"></span>
                                            </a>
                                        </figure>
                                    <?php } ?>
                                    <!--END .slider -->
                                </div>           
                        <?php endif; ?>

What I need to do is to add a DIV wrap around “the_content” if and only if the $project_photos selector is active, not being a PHP developer this is what I’ve come up with but it doesn’t work:

Read More
<div class="content_block">

                <?php if ( $project_photos() ) {

                        echo '<div class="project_description">';
                        the_content(); 
                        echo '</div>';

                    } else {

                        the_content(); 

                    } ?>

                <div class="<?php echo $left_block; ?>">

                    <?php  $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
                        if ( $project_photos ) : ?>
                                <div class="grid_gallery clearfix">
                                    <?php foreach( $project_photos as $project_photo ) { ?>
                                        <figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
                                            <a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto">
                                                <img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
                                            <span class="zoom-icon"></span>
                                            </a>
                                        </figure>
                                    <?php } ?>
                                    <!--END .slider -->
                                </div>           
                        <?php endif; ?>

If anyone could provide some guidance on how I might accomplish this I would be very grateful.

Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Can you give this a try?

     <div class="content_block">
    
                    <?php 
                            $project_photos = get_post_meta( get_the_ID(), 'project_photo_photo' );
    
                            if ( $project_photos ) {
    
                            echo '<div class="project_description">';
                            the_content(); 
                            echo '</div>';
    
                        } else {
    
                            the_content(); 
    
                        } ?>
    
                    <div class="<?php echo $left_block; ?>">
    
                        <?php
                            if ( $project_photos ) : ?>
                                    <div class="grid_gallery clearfix">
                                        <?php foreach( $project_photos as $project_photo ) { ?>
                                            <figure class="gallery_item featured-thumbnail thumbnail single-gallery-item">
                                                <a href="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" class="image-wrap" rel="prettyPhoto[gallery]">
                                                    <img class="project_photo_photo" width="260" src="/brv2/wp-content/files_mf/<?php echo $project_photo; ?>" alt="<?php the_title(); ?>" />
                                                <span class="zoom-icon"></span>
                                                </a>
                                            </figure>
                                        <?php } ?>
                                        <!--END .slider -->
                                    </div>           
                            <?php endif; ?>