Wordpress - 检查当前页面是否有标签 ID [英] Wordpress - check if current page has given tag ID
本文介绍了Wordpress - 检查当前页面是否有标签 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 WordPress 自定义分类法.
I am using WordPress custom taxonomies.
如何检查当前页面是否有tag_ID = "XXX"
?
How to check if the current page has tag_ID = "XXX"
?
如果这有帮助,管理页面上的 URL 如下所示:
If that is any help the URL on the admin page looks like this:
http://localhost/website/wp-admin/edit-tags.php?action=edit&taxonomy=company&tag_ID=13&post_type=news
当前使用的代码,但不工作:
The code currently used, but not working:
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
if (is_object_in_term($post - > ID, 'post_tag', '13')) {
// ID 13
}
if (is_object_in_term($post - > ID, 'post_tag', '12')) {
// ID 12
}
if (is_object_in_term($post - > ID, 'post_tag', '14')) {
// ID 14
}
}
推荐答案
这可能有用(对于 admin 中的给定 url)
May be this could be useful (for given url in admin)
global $pagenow;
if ($pagenow == 'edit-tags' && $_GET['tag_ID'] == '123') // 123 is for example
{
//
}
更新:前端
$tag_id=get_query_var('tag_id');
if($tag_id && $tag_id=='123') // 123 is for example
{
// code
}
这篇关于Wordpress - 检查当前页面是否有标签 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文