How to create category page

时间:2012-07-05 作者:Juan Lie

任何人都可以帮我制作一个分类页面。非常感谢。

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

你会想在你的主题category.php 文件:

<?php
// fetch the categories with the parent being the current cat
$sub_cats = get_terms(\'category\', array(
    \'parent\' => get_queried_object_id()
));
if(!is_wp_error($sub_cats) && $sub_cats)
{
    foreach($sub_cats as $cat)
    {
        // Create your grid here, this is just an example
        printf(
            \'<a href="%s">%s</a>\',
            get_term_link($cat, $cat->taxonomy),
            $cat->name
        );
    }
}

SO网友:Jonathan

This may be something you are looking for:

http://wordpress.org/support/topic/how-to-display-the-child-category-of-a-specific-parent-category

Which would be something along these lines:

$args = array( \'cat\' => yourcatid, \'post_parent\' => $post->ID, \'number_of_posts\' => -1 );

$posts = get_posts($args);

foreach($posts as $post)
{
?>
    <a href="<?php echo get_permalink($post->ID); ?>">
    <?php echo $post->the_title; ?>
    </a>
    <p><?php echo $post->the_excerpt; ?></p>
<?php } ?>

This would go into the template you use for the the sub-category

结束

相关推荐

WP_LIST_CATEGORIES()排除除一个类别外的所有类别

有没有办法排除除一个类别之外的所有类别?我想显示一个类别和它的子类别作为下拉菜单,但管理员可能会添加更多的子类别,所以我不想限制他们可以放在那里的唯一ID。所以我想排除除1及其子类别之外的所有类别。wp\\u list\\u categories()是否可以这样做?