How to include custom post-type templates and post-formats in the loop?
-
Hi everyone,
I’m not very code-savvy, but I managed to build myself a website with a custom post-type and a post-format. Sadly I can’t figure out how to incorporate them into the loop properly.
There are two post-types supposed to appear in the loop.
- Regular Posts
- Projects
I’ve got that working already, by adding this to my functions.php:
<?php add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( ( is_home() && $query->is_main_query() ) || is_feed() ) $query->set( 'post_type', array( 'post', 'project' ) ); return $query; }?>
My loop looks like this:
<?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content-post'); ?> <hr> <?php endwhile; ?> <?php else : ?> <?php get_template_part( 'content-none'); ?> <?php endif; ?>
The thing is, that each post-type uses it’s own template. Posts use content-post.php projects use content-project.php.
However since I have no idea how to include the projects-template, both posts and projects are displayed within the post-template.There is another thing. For the regular post I’ve got the post-format “aside” enabled. This has to be included, as well.
Can anybody give me a hint on that?
- The topic ‘How to include custom post-type templates and post-formats in the loop?’ is closed to new replies.