0
votes

I'm hoping that someone can help me out here. I am trying to get ACF integrated into a Theme a client purchased.

The basic functionality is that I have built a custom field on every post to choose where to place the post. Thus, if they choose “Option A” in the post, then the code needs to check for that option to be true before passing all of the content related to the post (Title, Content, Images, etc.)

A basic code example of how this would work in a standard php document would be as follows:

<?php if (have_posts()): while (have_posts()) : the_post(); ?>
   <?php if(get_field('pick_your_theme') == "Theme1") { ?>

         <h2><?php the_title(); ?></h2>
         <p><?php the_excerpt(); ?></p>

   <?php } ?><?php endwhile; ?>
<?php endif; ?>

The issue here is that the theme author has created the page in one giant open PHP function rather than breaking it up (as in example code 1 above) where I can easily insert the selector get_field.

Below is a link for the PHP code for the page:

http://pastebin.com/wyWQiQvx

2
The post that you put in paste bin doesn't look particularly different than the sample code, except that the theme author uses "echo" rather than closing PHP tags.Chris Herbert

2 Answers

0
votes

Normally you should already be able to access ACM fields within the loop using the following code:

<?php the_field('NAME_OF_FIELD'); ?>

0
votes

Building on @ChrisHerbert's comment, it should be a simple matter of sneaking your conditional in there, so the loop section of your code looks something like this:

if ( have_posts() ){ while (have_posts()){ the_post();
            if(get_field('pick_your_theme') == "Theme1") {  
                                            if( $gdl_show_title != "No" ){
                                                    echo '<div class="sixteen columns mb0">';
                                                    echo '<div class="page-header-wrapper">';
                                                    echo '<h1 class="page-header-title title-color gdl-title">' . get_the_title() . '</h1>';
                                                    echo '<div class="header-gimmick mr0"></div>';
                                                    echo '<div class="clear"></div>';
                                                    echo '</div>'; 
                                                    echo '</div>'; // sixteen columns                                                              
                                            }

                                            if( $page_background != 'No' ){
                                                    echo "<div class='sixteen columns'>";
                                                    echo '<div class="page-bkp-frame-wrapper">';
                                                    echo '<div class="page-bkp-frame">';
                                            }      

                                            $content = get_the_content();
                                            // Show content
                                            if( $gdl_show_content != 'No' && !empty($content) ){
                                                    echo '<div class="sixteen columns">';
                                                    echo '<div class="gdl-page-content">';
                                                    echo '<div class="bkp-frame-wrapper">';
                                                    echo '<div class="bkp-frame p20">';                                                    
                                                    the_content();
                                                    echo '</div>';                         
                                                    echo '</div>';         
                                                    echo '</div>'; // page-content
                                                    echo '</div>'; // sixteen columns
                                            }

                             } //pick_your_theme conditional

                      } // while loop

         } //if have posts 

Clearly you can customize the code within the 'pick_your_theme' conditional to meet you needs and add a } elseif(get_field('pick_your_theme') == "Some_Other_Theme") { or a default for when 'pick_your_theme' isn't set } else { block in there as needed.