My Issue:
If I browse to http://mysite/category/mycategory
, the if (is_category())
content isn’t displayed, the if(is_archive())
is shown instead.
My code:
archive.php
:
<?php include('includes/resultlist.php')?>
search.php
:
<?php include('includes/resultlist.php')?>
includes/resultlist.php
:
<?php get_header(); ?>
<div class="main">
<?php if (is_archive()) { ?>
<h1>Artigos publicados em <?php single_month_title(' '); ?></h1>
<?php } else if (is_search()) { ?>
<h1>Resultados para "<?php the_search_query(); ?>"</h1>
<?php } else if (is_category()) { ?>
<h1>Resultados para categoria "<?php the_category(); ?>"</h1>
<?php }
if ( have_posts() ) while (have_posts()) { the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
por <span class="date"><?php the_author(); ?></span> em
<span class="date"><?php the_date(); ?></span>
<p><?php echo get_the_excerpt(); ?> <a href="<?php the_permalink(); ?>">Leia mais</a></p>
<?php }
else {?>
<h2>Nada encontrado</h2>
<p>Desculpe, não encontramos o que você procurava!</p>
<?php }
include('pagination.php');
?>
</div><!-- /main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
What I tried:
Created a category.php
file with the contents: <?php include('includes/resultlist.php')?>
but the issue persits. I included some garbage text on the end of category.php and it shows on the end of the rendered page, so the file is being called, I suppose.
My environment:
LAMP Ubuntu 64 bit with apache, mysql and php installed with default options via apt-get.
A category page is an archive page. So
is_archive()
willreturn true
on a category page. Try to push downis_category()
further, or useis_category()
beforeis_archive()
.Like This