Wordpress 打印类别打印阵列?
我正试图用这个代码打印类别,但它一直在打印数组Wordpress 打印类别打印阵列?,wordpress,categories,Wordpress,Categories,我正试图用这个代码打印类别,但它一直在打印数组 <?php $posts = get_posts('category=1&orderby=desc'); foreach($posts as $post) { ?> <a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a><br /><?php
<?php $posts = get_posts('category=1&orderby=desc'); foreach($posts as $post) { ?>
<a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a><br /><?php print(get_the_category($id)); ?>
<?php } ?>
谢谢…一篇文章可能属于多个类别,因此将返回一个数组,因为它是一个对象数组。 下面是文档中的一个示例
<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
foreach($categories as $category) {
$output .= '<a href="'.get_category_link($category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
}
echo trim($output, $separator);
}
?>