• Hi guys I would like to put several pages content in my index.php, so I use page-{slag} calling specific page trough get_template_part(). But the thing is that in my specific pages I used the_field() from Advance Custom Filed plugin. And content I dont see. I see that browser rendered div-s and so but content of the_field disappears. How I can solve this ?
    the code of index.php

    <?php
    
    		if ( have_posts() ) : the_post();?>
    
    			<div> <?php get_template_part( 'page', 'shop' ); ?></div>
    
    		<?php endif; ?>

    And code of page-shop.php

    <div class="container-fluid "> <!-- play section -->
    
    				<div class="row">
    					<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
    						<h2 class="" style="text-transform:uppercase"><?php the_field('shop_name');?></h2>
    					</div>
    					<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
    						<h2 class="" style="text-transform:uppercase"><?php the_field('shop_category');?></h2>
    					</div>
    					<div class="col-xs-10 col-sm-10 col-md-7 col-lg-7  ">
    						<?php  $image = get_field('shop_item1');
    
    						if( !empty($image) ): ?>
    
    							<img class=" img-responsive" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    
    						<?php endif;?>
    					</div>
    
    				</div> <!-- row -->
    			</div>
    • This topic was modified 8 years, 5 months ago by tigtig.
Viewing 2 replies - 1 through 2 (of 2 total)
  • First of all, I’d try to use the global $post in the template part. So, here’s my suggestion for your page-shop.php:

    
    <?php global $post; ?>
    <div class="container-fluid"><!-- play section -->
        <div class="row">
            <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
    	    <h2 style="text-transform:uppercase"><?php the_field( 'shop_name', $post->ID );?></h2>
            </div>
            <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
    	    <h2 style="text-transform:uppercase"><?php the_field( 'shop_category', $post->ID );?></h2>
            </div>
            <div class="col-xs-10 col-sm-10 col-md-7 col-lg-7">
                <?php
                $image = get_field( 'shop_item1', $post->ID );
                if ( ! empty( $image ) ) : ?>
                <img class="img-responsive" src="<?php echo $image['url']; ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" />
                <?php endif; ?>
            </div>
        </div><!-- row -->
    </div>
    

    You should even ignore the first line of my suggestion above because I forgot WordPress already includes that global when you call get_template_part ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How show the_field() function’s content ACF via get_template_part()’ is closed to new replies.