Home Forums Front-end Issues Display Relationship Posts in Grid


Display Relationship Posts in Grid

  • Hello everyone, I’m new to this plugin – it seems I’m late to the party!

    I am trying to display a related posts grid on to my WooCommerce single product pages. I can see that this has been asked before, but I’m not quite seeing the results that I’d like.

    I’ve managed to create the field to allow me select the posts within the product page. I’ve also been able to reflect those posts on the front end, but it’s being shown in a list style. I would like it to show as a grid – just the way the default WooCommerce related products appear. With a photo on top, and the title below.

    Can anyone offer some guidance on this? Thank you in advance!

  • I’ve finally figured it out. This is what I used to be able to show my related posts on WooCommerce product pages:

    $vendorposts = get_field('related_posts');
    if( $vendorposts ): ?>
        <div class="latest_post_holder boxes three_columns two_rows">
        <?php foreach( $vendorposts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
                        <?php if ( has_post_thumbnail( $rp->ID ) ) : ?>
    	  <?php echo get_the_post_thumbnail( $rp->ID, 'regular-posts' ); ?>
    <?php else : ?>
    	  <img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />	
    	<?php endif; ?>
    	            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php endforeach; ?>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display Relationship Posts in Grid’ is closed to new replies.