Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Milan BetmencicCourses Plus Student 51 Points
I have couple of custom post types and I want to create page that will show their posts on one page, like a list...
So I read that I need to create -archive.php- or it is -archives.php- files as template, so I did that...
Then I read that to access them I would go to -my url/news- if my custom post type is news, but I keep redirecting to index.php and not archive file?
Can you please help me out?
Raymon Oleaga19,298 Points
So you basically want to display the posts on a custom post type on page? I don't believe you need the archives.php for that. You can actually display them in any page you want.
Are you adding the WP_query to you the you want the custom post type to display?
so your page would look something like this:
<?php while ( have_posts() ) : the_post(); ?> <?php the_title(); ?> <?php the_content(); ?> <?php endwhile; // end of the loop. ?> <?php wp_reset_postdata(); $args = array ( 'post_type' => 'name of the post type here' ); $the_query = new WP_Query ($args); ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(); ?> <?php the_excerpt('name of the post type'); ?> <?php the_permalink() ?> <?php endwhile; // end of while ?>
Also check out this part of the WP Theme track:
You should check all the videos from that part of the course
Hope it helps!