I’ve got seperate templatefiles for my teasers, eg. teaser_small, teaser_medium… with – just in a short – code like this:
<article>
<a href="<?php the_permalink(); ?>">
<?php get_template_part('templates/entry-teaserimage'); ?>
<h3><?php get_template_part('templates/entry-meta'); ?></h3>
<h1><?php the_title(); ?></h1>
</a>
</article>
On the homepage i wanted to make a special layout, with differnt groups of teasers, selectable by the autor. So i set up a flexible contententfield with different layouts, each of them uses a repeaterfield with a relations to posttype post.
And within this relation-posttypefield, i tried to use my templatefile, which is used in other cases as well.
if ( get_row_layout() == 'modul_s' ) {
$post_objects = get_sub_field('article');
if( $post_objects ): ?>
<div>
<?php foreach( $post_objects as $post):
setup_postdata($post);
get_template_part('templates/teaser-small', get_post_format());
wp_reset_postdata();
endforeach; ?>
</div>
<?php endif;
}
what ends up in Notice: Trying to get property of non-object…
The other method with ‘get_permalink($postobject->ID)’ doesn’t work properly, because the IDs can’t be passed…
is there a way to optimise it, except dirty workarounds with selfwritten functions for all articlefields and including the template via
include(locate_template('templates/teaser-small.php'));