Wordpress 获取类别链接 [英] Wordpress get category link

查看:24
本文介绍了Wordpress 获取类别链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下如何获取每个类别的相关帖子的链接.我只有一些只会显示父类别的代码.任何帮助将非常感激.谢谢!

I want to ask on how to get the link of each category that have related post on it. I only got some code that will only display parent category. Any help would be much appreciated. Thanks!

$categories = get_categories();

foreach ($categories as $cat){
   if($cat->parent < 1){
      echo $cat->cat_name ;
   }
}

?>

推荐答案

听起来您可能想要 get_category_link -- 类似

Sounds like you may want get_category_link -- something like

$categories = get_categories();
foreach ($categories as $cat) {
   $category_link = get_category_link($cat->cat_ID);
   echo '<a href="'.esc_url( $category_link ).'" title="'.esc_attr($cat->name).'">'.$cat->name.'</a>';
}

应该为您打印出类别的链接.

should print out the links to the categories for you.

这篇关于Wordpress 获取类别链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆