You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为WordPress的taxonomy分类法链接添加锚点#here

错误原因

  • 语法错误:你在$term->term_id后多余添加了英文分号,将完整的赋值语句截断,后续拼接代码变为无效独立语句,触发PHP致命错误。
  • 无效变量:代码中并未定义$anchor变量,无需额外添加该变量,直接在链接末尾拼接目标锚点#here即可。

修正后可正常运行的代码

add_filter('term_link', function ($termlink, $term, $taxonomy) {
   
    // 处理 property_type 分类链接
    if ('property_type' == $taxonomy) {
        $termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_type:' . $term->term_id . '#here';
    }
    
    // 处理 property_city 分类链接
    if ('property_city' == $taxonomy) {
        $termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_city:' . $term->term_id . '#here';
    }
    
    return $termlink;
}, 10, 3);

如果需要后续使用动态锚点,只需提前定义锚点变量替换代码中的#here即可。

内容的提问来源于stack exchange,提问作者neosan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 14:06:00