I made two pages, a front page and an "basic content page".
On this "basic content page", I made a flexible content with different text and images.
I search for a way to display the last row on the front page, is it possible ?
UPDATE : Here is the last code, it can grab the content from another page using "post object field" (named "relation") thanks to @Nick Surmanidze. Only remain the question of how to grab the last row.
<?php
$post_object = get_field('relation');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<div>
<?php
// check if the flexible content field has rows of data
if( have_rows('selection') ):
// loop through the rows of data
while ( have_rows('selection') ) :
the_row();
if( get_row_layout() == 'selectionselection' ):
?>
<div class="titre-soustitre">
<div class="menu-content" data-id="id-<?php the_sub_field('id'); ?>">
<p class="demo bis"><span class="sub"> </span></p>
<a href="#" class="expander"><h1><p class="demo title"><?php the_sub_field('title'); ?></p></h1></a>
<p class="demo bis"><span class="sub"><?php the_sub_field('subhead'); ?></span></p>
</div>
</div>
<?php
endif;
endwhile; else :
// no layouts found
endif;
?>
</div>
<?php wp_reset_postdata();// IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
UPDATE 2 : In order to help you understanding: Here is the ROW of the other page, that I am grabbing through $post_object
<?php
// check if the flexible content field has rows of data
if( have_rows('selection') ):
// loop through the rows of data
while ( have_rows('selection') ) : the_row();
if( get_row_layout() == 'selectionselection' ):?>
<div class="titre-soustitre">
<div class="menu-content" data-id="id-<?php the_sub_field('id');?>">
<p class="demo bis"><span class="sub"> </span></p>
<a href="#" class="expander"><h1><p class="demo title"><?php the_sub_field('title');?></p></h1></a>
<p class="demo bis"><span class="sub"><?php the_sub_field('subhead');?></span></p>
</div>
</div>
<?php endif;
endwhile;
else :
// no layouts found
endif;
?>