我在一个网站上工作,该网站使用类别将内容分组为“问题”。主页通过拉取ID最高的类别(因此是最新的)来显示最新的问题。
我想做的是在下面类别循环中的帖子之前显示类别标题和描述。有人能给我指出正确的方向吗?
<?php $issue = get_terms(\'category\', \'orderby=ID&order=DESC&number=1&child_of=3\'); $latest_issue = $issue[0]->term_taxonomy_id; ?>
<?php query_posts(array( \'category__in\' => $latest_issue )); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(\'clearfix\'); ?> role="article">
<header class="home-header">
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( \'wpbs-featured\' ); ?></a>
</header> <!-- end article header -->
<section class="home-content clearfix">
<div class="home-content-header"><h1 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <span><?php the_author_posts_link(); ?></span></h1></div>
<section class="post_content home-excerpt clearfix">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
<?php endwhile; ?>
SO网友:Marcin Bazanowski
$category = get_category($latest_issue); // it is category object
echo $category->title;
echo $category->description;
在法典中:
http://codex.wordpress.org/Function_Reference/get_category 但我认为您不应该通过上次创建的ID来获取类别,而应该通过slug来获取类别:
http://codex.wordpress.org/Function_Reference/get_category_by_slug
因此,您应该更改:
<?php $issue = get_terms(\'category\', \'orderby=ID&order=DESC&number=1&child_of=3\'); $latest_issue = $issue[0]->term_taxonomy_id; ?>
<?php query_posts(array( \'category__in\' => $latest_issue )); ?>
至
<?php $issue_category = get_category_by_slug(\'issue\'); ?>
<?php query_posts(array( \'category__in\' => $issue_category->term_id )); ?>
要打印类别标题和说明:
echo $issue_category->title;
echo $issue_category->description;