当前位置:网站首页>WordPress obtains category name and link through category ID

WordPress obtains category name and link through category ID

2022-06-21 08:14:00 Ashi

stay Wordpress In the process of theme development , In especial CMS Layout of topic classification , Select classification through background options , The foreground calls the classified ID To get the name and link of the category , At this point we will use get_cat_name() and get_category_link() Two functions , And vice versa get_cat_ID() Function to get the classification ID.

get_cat_name() Function usage :

<?php get_cat_name( $cat_id )?>

$cat_id It's all the parameters , For example, get classification ID by 1 The name of :

<?php echo get_cat_name(1);?>

get_category_link() Function usage :

<?php get_category_link( $cat_id )?>

$cat_id It's all the parameters , For example, get classification ID by 1 Link to :

<?php echo get_category_link(1);?>

get_cat_ID() Function usage :

<?php get_cat_ID( $cat_name )?>

$cat_name It's all the parameters , For example, get the category name as ‘Category Name’ Of ID:

<?php echo get_cat_ID('Category Name');?>

If no classification is specified ID, There will be problems with the quantity obtained , By designation ID It is more convenient :

<?php echo wt_get_category_count($cat_id ); ?>

Generally, these options are obtained through background options , Output classification ID Just go straight through get_cat_name() and get_category_link() Function to convert to names and links ,

原网站

版权声明
本文为[Ashi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221502095440.html