• I have a slider that could include 3 different types of content pulled from advanced special fields. The reason I say “advanced” is because Im using the advanced custom fields plugin. That is why it used “the_field” instead of “get_post_meta”.

    Here is my code that currently displays everything but I want it to only display one item based on the fact that the others would be empty.

    <div id="slides">
    <?php query_posts(array('post_parent' => $post->ID, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
    <div class="slide">
    
    <!-- if navigation_main_image -->
    <a href='<?php the_permalink() ?>' rel="bookmark"><img src="<?php the_field('navigation_main_image') ?>" /></a>
    
    <!-- if page_image -->
    <a href='<?php the_permalink() ?>' rel="bookmark"><img src="<?php the_field('page_image') ?>" /></a>
    
    <!-- if content_image -->
        <div id="contentimg"><img src="<?php the_field('content_image') ?>" /></div>
            <div id="contenttext">
            <h1 class="entry-title"><?php the_title(); ?></h1>
            <?php the_content(); ?>
            </div>
    <div style="clear:both"></div>
    
    </div>
    <?php } ?>
    </div>

    Please any help would be awesome!! Thank You!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter product247

    (@product247)

    Anyone??

    Thread Starter product247

    (@product247)

    I FIGURED IT OUT!!! (one explanation point for each day it took)

    <div id="slides">
    
    <?php query_posts(array('post_parent' => $post->ID, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
    
    <?php $navigation_main = get_field('navigation_main_image'); ?>
    <?php $page = get_field('page_image'); ?>
    <?php $content = get_field('content_image'); ?>
    
    <div class="slide">
    <?php if($navigation_main) { ?>
    <a href='<?php the_permalink() ?>' rel="bookmark"><img src="<?php the_field('navigation_main_image') ?>" /></a>
    
    <?php } elseif($page) { ?>
    <img src="<?php the_field('page_image') ?>" />
    <?php } else { // You can remove this line and the two below if you don't need them - just leave the first "}" (ignore quotes) ?>
    	    <div id="contentimg"><img src="<?php the_field('content_image') ?>" /></div>
            <div id="contenttext">
            <h1 class="entry-title"><?php the_title(); ?></h1>
            <?php the_content(); ?>
            </div>
    <div style="clear:both"></div>
    <?php } ?>
    
    </div>
    <?php } ?>
    </div>

    This helped me, thank you!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Else and ElseIf With Advanced Page Fields’ is closed to new replies.