我想问如何让每一个有它相关的职位类别的链接。 我只得到了一些代码,将只显示父类别。 任何帮助将非常感激。 谢谢!
<?php
$categories = get_categories();
foreach ($categories as $cat){
if($cat->parent < 1){
echo $cat->cat_name ;
}
}
?>
我想问如何让每一个有它相关的职位类别的链接。 我只得到了一些代码,将只显示父类别。 任何帮助将非常感激。 谢谢!
<?php
$categories = get_categories();
foreach ($categories as $cat){
if($cat->parent < 1){
echo $cat->cat_name ;
}
}
?>
听起来像你可能想get_category_link -像
$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>';
}
应打印出链接到的类别为您服务。
根据Function Reference/get category link
<?php get_category_link( $category_id ); ?>
例:
<?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>