获取活动页面的当前类别ID
问题描述:
希望在WordPress中提取特定页面的类别ID,该ID列出了使用该特定类别的所有帖子.尝试以下内容,但不起作用.我可以使用single_term_title
获取类别名称.
Looking to pull the category ID of a specific page in WordPress that is listing all posts using that specific category. Tried the below but not working. I am able to get the category name using single_term_title
.
$category = single_term_title("", false);
$catid = get_cat_ID( $category );
$category
例如显示娱乐".但是我还需要娱乐"的ID.我该怎么办?
$category
is displaying "Entertainment" for example. But I also need the ID of "Entertainment". How would I go about this?
答
您可以尝试使用 get_the_category()
:
You can try using get_the_category()
:
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;