Answer the question
In order to leave comments, you need to log in
How to set a separate template for a taxonomy category?
Created custom post type = company. It created a taxonomy = category. Taxonomy categories can be several: 1,2,3. How to display separate templates for posts of these three categories?
Now there is a single-company.php file in which the template is displayed:
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'single-category' );
if( wp_get_post_terms() === '1' ){
get_template_part( 'template-parts/content', '1' );
}
else {
get_template_part( 'template-parts/content', '2' );
}
Answer the question
In order to leave comments, you need to log in
Если почитать про wp_get_post_terms, то можно заметить, что эта функция возвращает массив. Причем массив объектов. Вам нужно задать нужные аргументы, чтобы получить только айдишники таксономий, после чего забрать нулевой элемент массива и вот тогда уже можно проверять его на соответствие.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question