2013-02-27 75 views
0

我试图打印与此代码的类别,它不断打印数组?打印类别打印数组?

<?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 } ?> 

谢谢...

回答

2

阿交可在一个以上的类别,因此一个阵列被进一步退回它是对象的数组。 以下是文档中的示例。

<?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); 
} 
?>