2009-11-14 79 views

回答

5

如果你想在帖子页面上做到这一点,你可以添加如下内容到你的主题的single.php文件中。

<div class="meta">Posted in: <span><?php the_category(', ') ?> </span></div> 
1

这里的一些信息,这将是有用的:

http://codex.wordpress.org/Template_Tags/wp_list_categories

基本上你可以拨打:<?php wp_list_categories($args); ?>,这将输出你在找什么。

Thr $args参数是一组设置字符串,可让您在返回的链接上更改顺序,样式,深度等。

2

请注意:<?php the_category(', ') ?>将显示类别作为链接。这是很好的....但如果你只想要类别的网址(即只有类别链接),那么你将不得不使用<?php get_category_link($category_ID); ?>$category_ID是必需的。一旦你解决了,类别的URL将被返回。

考虑例如:

<?php 
    // Get the ID of a given category 
    $category_id = get_cat_ID('Category Name'); 

    // Get the URL of this category 
    $category_link = get_category_link($category_id); 
?> 

<!-- Print a link to this category --> 
<a href="<?php echo esc_url($category_link); ?>" title="Category Name">Category Name</a> 

现在你可以看到我们是如何走到类别ID,然后用它来获取类别链接。
希望这可以很好地回答你的问题吗?