I am taking care of a news site in WordPress and I noticed that when more than one category is selected by subject of the following conflict:
BytheURLI'montheLifestylecategorypageonlyitreturnstheHealth/Beautymatter.Thesesubjectsaremarkedascategory:Lifestyle,Health/Beauty.Thisisthecodeforthecategoriespage
get_header();?><divid="primary" class="content-area">
<main id="main" class="site-main">
<div class="container">
<div class="row">
<?php
if ( have_posts() ) : ?>
<header class="page-header">
<?php
$args = array(
'category_name' => $slug
);
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$cor = get_field('cor', $term );
$slug = $term->slug;
endif;
?>
<h1 style="color:<?php echo $cor; ?>" class="page-title tac"><?php echo $term->name; ?></h1>
</header><!-- .page-header -->
<!-- Notícia em destaque -->
<!-- Notícia sozinha na DIV -->
<?php
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$slug = $term->slug;
endif;
// The Query
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'category_name' => $slug
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
$cols = 0;
$ids = array();
while ( $query->have_posts() ) : $query->the_post();
$ids[] = get_the_ID();
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$cor = get_field('cor', $term );
endif;
?>
<div class="col-md-6">
<a href="<?php echo get_permalink(); ?>">
<h1 class="title-main" style="color:<?php echo $cor; ?>">
<?php echo get_field('titulo_chamada'); ?>
</h1>
</a>
<a href="<?php echo get_permalink(); ?>">
<div class="img-destaque img-responsive" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
<div class="tag-category branco" style="background-color: <?php echo $cor; ?>">
<?php echo $term->name; ?>
</div>
</div>
</a>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
<!-- PUBLICIDADE -->
<div class="col-md-6 col-xs-12 img-responsive mw100pc" style="float: right;">
<?php echo do_shortcode("[pro_ad_display_adzone id=1043]"); ?>
</div>
<!-- Quatro primeiras notícias -->
<div class="col-md-12">
<div class="row">
<?php
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$slug = $term->slug;
endif;
// The Query
$args = array(
'post_type' => 'post',
'post__not_in' => $ids,
'posts_per_page' => 4,
'category_name' => $slug,
‘showposts’ => 1,
‘paged’=>$paged
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
$cols = 0;
while ( $query->have_posts() ) : $query->the_post();
$ids[] = get_the_ID();
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$cor = get_field('cor', $term );
endif;
?>
<div class="col-md-3" style="height: 620px;">
<a href="<?php echo get_permalink(); ?>">
<h1 class="title-main" style="color:<?php echo $cor; ?>">
<?php echo get_field('titulo_chamada'); ?>
</h1>
</a>
<a href="<?php echo get_permalink(); ?>">
<div class="img-destaque" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
<div class="tag-category branco" style="background-color: <?php echo $cor; ?>">
<?php echo $term->name; ?>
</div>
</div>
</a>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
</div>
</div>
<!-- Resto das noticias da categoria -->
<div class="col-md-12">
<div class="slide-noticias">
<?php
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$slug = $term->slug;
endif;
// The Query
$args = array(
'post_type' => 'post',
'post__not_in' => $ids,
'posts_per_page' => 4,
'category_name' => $slug,
‘showposts’ => 1,
‘paged’=>$paged
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
$cols = 0;
while ( $query->have_posts() ) : $query->the_post();
$ids[] = get_the_ID();
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$cor = get_field('cor', $term );
endif;
?>
<div class="col-md-3" style="height: 620px;"><a href="<?php echo get_permalink(); ?>">
<h1 class="title-main" style="color:<?php echo $cor; ?>"><?php echo get_field('titulo_chamada'); ?></h1></a>
<a href="<?php echo get_permalink(); ?>">
<div class="img-destaque" style="background-image: url(<?php the_post_thumbnail_url(); ?>); ">
<div class="tag-category branco" style="background-color: <?php echo $cor; ?>"><?php echo $term->name; ?></div>
</div>
</a>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
</div>
</div>
<!-- Paginação -->
<div class="clear"></div>
<br />
<br />
<!--BANNER-->
<div class="col-xs-12 img-responsive" id="closer">
<?php echo do_shortcode("[pro_ad_display_adzone id='1049' class='banner-categoria']"); ?>
<a hrfe="#" class="modal-close hidden-xs" onclick="document.getElementById('closer').style.display='none'"></a>
</div> <!-- /.publicidade -->
<div class="clear"></div>
<!-- PROVISÓRIO -->
<hr>
<?php
// The Query
$args = array(
'post_type' => 'post',
'category_name' => $term->slug,
'post__not_in' => $ids,
'posts_per_page' => 10
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
$colun = 1;
while ( $query->have_posts() ) : $query->the_post();
$terms = get_the_terms( get_the_ID(), 'category');
if( !empty($terms) ) :
$term = array_pop($terms);
$cor = get_field('cor', $term );
endif;
?>
<?php if($colun == 1 or $colun == 6) : ?><div class="col-md-6"><?php endif; ?>
<a href="<?php echo get_permalink(); ?>" style="color:<?php echo $cor; ?>"><h1 class="title-resume"><?php echo get_field('titulo_chamada'); ?></h1></a>
<?php echo get_the_date(); ?>
<hr>
<?php if($colun == 5 or $colun == 10) : ?></div><?php endif; ?>
<?php
$colun++;
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
endif;
?>
<?php endif; ?> <!-- DEVE PERMANECER NA PÁGINA -->
</main><!-- #main -->
</div><!-- #primary -->
<br />
<br />
<br />
<?php
get_footer();
?>
<script type="text/javascript" async src="https://d335luupugsy2.cloudfront.net/js/loader-scripts/7270b716-ffb6-4f76-8de0-9f09b12a4159-loader.js"></script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*newDate();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create','UA-68151385-5','auto');ga('send','pageview');</script><script>$('.slide-noticias').slick({infinite:true,slidesToShow:4,slidesToScroll:4,dots:true,infinite:false,speed:300,slidesToShow:4,slidesToScroll:4,responsive:[{breakpoint:1024,settings:{slidesToShow:3,slidesToScroll:3,infinite:true,dots:true}},{breakpoint:600,settings:{slidesToShow:2,slidesToScroll:2}},{breakpoint:480,settings:{slidesToShow:1,slidesToScroll:1}}//Youcanunslickatagivenbreakpointnowbyadding://settings:"unslick"
// instead of a settings object
]
});
</script>