I have a custom post type named STORIES.
Within that post type, I have categories, so each STORY is also assigned a category like this…
Story 1 (assigned category RED)
Story 2 (assigned category BLUE)
Story 3 (assigned category GREEN) etc.
I need to display a page which lists the categories, and when clicked, then lists the posts from that category.
So the page would be a list with…
RED
BLUE
GREEN
What template would control this list?
Then I click on RED and it takes me to a template that displays only the RED Stories.
What template would control this list?
I am guessing I need three specific templates?
One called template-stories.php and one called archive-stores.php and a final one called single-stories.php?
you are guessing right, first you need a page template where you are going to call your terms, but you need to call by his taxonomy, right?, To do that, you need to use the function
get_terms( $taxonomies, $args );
, and with the functionget_term_link($term)
, you are going to obtain the url of the current term:}
Then, you need the archive.php where you are going to display all posts associated to this current term.
But first you need to get the current term, and you can do it using the function
get_term_by($field, $value, $taxonomy, $output, $filter)
.Now you can make an if statement: