How to display custom post types AND regular posts separately on a shared taxonomy archive?

admin2025-01-07  5

I've looked over numerous questions and answers on problems somewhat related to this but can't seem to find the same situation or solution.

I have a custom taxonomy that needs to have an archive page that can display both custom post types and regular posts, but not in the same section. Basically there needs to be a clear difference between the CPT-posts and regular posts.

For example, if "movie guides" is the custom taxonomy, "ben affleck" is a movie guide, and "Movies" are custom post types on: website/movie-guides/ben-affleck

I would like that page to also have regular posts that are in the "ben affleck" movie guide taxonomy, but at the bottom of the page, in a different section for regular posts/post thumbnails. So part of the page would have Movies (posts from the CPT "Movies") with Ben Affleck, and after that would be post snippets from posts about Ben Affleck.

I've found information to just pull both types of posts on the same page together, but wasn't sure how to separate them in the template which is what I'm really looking for.

UPDATE: So far I've taken part of the theme's default category template and created taxonomy-{taxonomy_slugname}.php, which has pulled the CPTs onto the page, but now I can't figure out how to add posts since it's pulling the CPT's via "get post." My theme is Braxton, if that helps.

I've looked over numerous questions and answers on problems somewhat related to this but can't seem to find the same situation or solution.

I have a custom taxonomy that needs to have an archive page that can display both custom post types and regular posts, but not in the same section. Basically there needs to be a clear difference between the CPT-posts and regular posts.

For example, if "movie guides" is the custom taxonomy, "ben affleck" is a movie guide, and "Movies" are custom post types on: website.com/movie-guides/ben-affleck

I would like that page to also have regular posts that are in the "ben affleck" movie guide taxonomy, but at the bottom of the page, in a different section for regular posts/post thumbnails. So part of the page would have Movies (posts from the CPT "Movies") with Ben Affleck, and after that would be post snippets from posts about Ben Affleck.

I've found information to just pull both types of posts on the same page together, but wasn't sure how to separate them in the template which is what I'm really looking for.

UPDATE: So far I've taken part of the theme's default category template and created taxonomy-{taxonomy_slugname}.php, which has pulled the CPTs onto the page, but now I can't figure out how to add posts since it's pulling the CPT's via "get post." My theme is Braxton, if that helps.

Share Improve this question edited Jul 17, 2014 at 10:19 howdydoo asked Jul 15, 2014 at 8:54 howdydoohowdydoo 11 bronze badge 5
  • Good question. What have you tried so far and where's your code? Have you read this codex.wordpress.org/Class_Reference/WP_Query – Brad Dalton Commented Jul 15, 2014 at 9:00
  • how would expect this to paginate, or would all results be on a single page? – Milo Commented Jul 15, 2014 at 15:59
  • @BradDalton I have but it doesn't seem to help. Updating my question with more information on what has been done. – howdydoo Commented Jul 17, 2014 at 10:17
  • @Milo I hadn't gotten to that part yet. I was hoping to have the CPT's paginate in a group of 9 or so, with the regular post snippets still below them/below the pagination. – howdydoo Commented Jul 17, 2014 at 10:17
  • The problem you'll have with pagination is that when the main query runs out of posts, subsequent pages will 404. Your secondary query can never have more posts than the main query. – Milo Commented Jul 17, 2014 at 14:05
Add a comment  | 

1 Answer 1

Reset to default 0

Use a new query outside the loop like this one

$query = new WP_Query( 'category_name=ben affleck;post_type=post' );

if ( $query->have_posts() ) : while $query->have_posts() : $query->the_post();

 // Loop output goes here

endwhile; endif;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261058a711.html

最新回复(0)