我试着用这个代码打印类别,但它一直在打印数组?
<?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 } ?>谢谢..。
发布于 2013-02-27 14:04:08
一个帖子可能在多个类别中,因此返回一个数组,而且它是一个对象数组。以下是文档中的一个示例。
<?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);
}
?>https://stackoverflow.com/questions/15103399
复制相似问题