任何人都可以帮我制作一个分类页面。非常感谢。
How to create category page
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
结束