Support » Plugins » apply template within loop

  • I’m trying to set up a WP install so that Admin users can create ‘blocks’ of content in the CMS – think promotional areas – and, from this library of blocks, add individual blocks to each page.

    I’m using custom post types and the CPTR plugin; this has solved most of the heavy lifting. We can now create custom posts, of type ‘Block’, and assign one or more of them to a page.

    The bit I’m struggling with is formatting the display of them. I’m pulling out the related ‘blocks’ for a page like this:

    $related_posts = cpr_populate($post->ID);
    if (count($related_posts) > 0){
    	foreach ($related_posts as $related_post){
    		setup_postdata($related_post);
    	}
    }

    I could then call the_content() or something to display each post’s content.

    But that ‘block’ post has a post-type. And I want to apply a template to it based on that post-type. If I’ve got a “single-block.php” template file, how can I get the code above to call it for each of the blocks it’s displaying?

  • The topic ‘apply template within loop’ is closed to new replies.