大家好! 好吧,我有这段代码,它显示了每个类别的一篇文章,但我只需要显示一篇文章,并且需要设置我正在尝试的类别的“名称”:
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0
);
$categories = get_categories($cat_args);
foreach($categories as $category) {
echo '<dl>';
echo '<dt> <a href="' . get_category_link( $category->name ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>';
$post_args = array(
'numberposts' => 1,
'category' => $category->term_id
);
$posts = get_posts($post_args);
foreach($posts as $post) {
?>
<dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd>
<div class="entry">
<?php the_content(); ?>
</div>
<?php
}
echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>View all posts in ' . $category->name.'</a></dd>';
echo '</dl>';
}
?>
然后我搜索了法典并没有找到按名称获取类别的方法,有人可以帮助我吗?