2

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.

  • What information is it showing instead? if(is_archive()) information? – Howdy_McGee Aug 16 '13 at 17:08
  • @Howdy_McGee Yes. I will update the question, thanks for reminding me! – That Brazilian Guy Aug 16 '13 at 17:09
5

A category page is an archive page. So is_archive() will return true on a category page. Try to push down is_category() further, or use is_category() before is_archive().

Like This

if ( is_search() )
{
    // Search Result content
}
elseif( is_category() )
{
    // Category archive content
}
// check for tag, taxonomy, date before 
elseif ( is_archive() )
{
    // Default archive content for *every* type of archive
}
else
{
    // Default content for non-archives
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.