显示的是IS_ARCHIVE()内容,而不是IS_CATEGORY()

时间:2013-08-16 作者:That Brazilian Guy

我的问题:

如果我浏览到http://mysite/category/mycategory, 这个if (is_category()) 未显示内容,the if(is_archive()) is shown instead.

我的代码:

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(); ?>
我尝试的内容:创建了category.php 包含以下内容的文件:<?php include(\'includes/resultlist.php\')?> 但问题仍然存在。我在分类的末尾添加了一些垃圾文本。php,它显示在呈现页面的末尾,因此我想正在调用该文件。

我的环境:

LAMP Ubuntu 64位,安装apache、mysql和php,通过apt get使用默认选项。

1 个回复
最合适的回答,由SO网友:Sisir 整理而成

A category page is an archive page. 所以is_archive()return true 在类别页面上。试着往下推is_category() 进一步,或使用is_category() 之前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
}

结束

相关推荐

Get categories without post

我想得到没有帖子的类别。下面是使用post获取类别的sql。。SELECT terms.term_id,terms.name,COUNT(post.ID) FROM wp_posts as post JOIN wp_term_relationships as rel ON post.ID = rel.object_ID JOIN wp_term_taxonomy as ttax ON rel.term_taxonomy_id = ttax.term_taxonomy_id JOI