4 php wordpress wordpress-theming
我正在尝试创建一个列出每个类别内容的单个页面.我已设法创建列表.我现在需要获得该类别的名称.我有以下代码:
<ul>
<li> CATEGORY NAME HERE </li>
<?php query_posts('cat=0'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
如何调用第一类的名称(0)?
当前编辑:为什么不会多次工作?
<div class="first-col">
<ul>
<?php query_posts('cat=0'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<li> <?php $category = get_the_category();
echo $category[0]->cat_name;
?> </li>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</div>
<div class="first-col">
<ul>
<li> <?php $category = get_the_category();
echo $category[0]->cat_name;?> </li>
<?php query_posts('cat=3'); ?>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
小智 12
您必须获取类别数组并回显数组中的第一个类别. http://codex.wordpress.org/Function_Reference/get_the_category
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
Run Code Online (Sandbox Code Playgroud)