Post a Story

Advanced Custom Fields – Code to Display Blog Post in a Template Using a Function

<div style=”margin-left:50px; padding-left:50px; width:400px;”>

<?php

$post_object = get_field(‘blog1’);

if( $post_object ):

// override $post
$post = $post_object;
setup_postdata( $post );

?>
<div>
<h3><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>

<?php the_post_thumbnail( ‘medium’ ); ?> </h3>

<?php echo wp_trim_words( get_the_content(), 60 );?>

</div>
<?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>

</div>

0 Comments

Leave a reply to Quentinimmaw Click here to cancel the reply

Your email address will not be published. Required fields are marked *

*

7712 Views
© RolePages / PebbleArt Inc. 2017

Log in with your credentials

or    

Forgot your details?

Create Account

Skip to toolbar