php - 如何将 Achnor 添加到分类链接
问题描述
我正在尝试在我的代码中放置一个锚点,以便链接指向#here
举个例子
mysite/property/?jsf=jet-engine&tax=property_type:9 #这里
add_filter('term_link', function ($termlink, $term, $taxonomy) {
// taxonomy type
if ('property_type' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_type:' . $term->term_id;
}
// taxonomy city
if ('property_city' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_city:' . $term->term_id;
}
return $termlink;
}, 10, 3);
在我看来,它必须是.$anchor. '#here';
但这似乎不是正确的方法..(PHP致命错误)
add_filter('term_link', function ($termlink, $term, $taxonomy) {
// taxonomy type
if ('property_type' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_type:' . $term->term_id; . $anchor . '#here';
}
// taxonomy city
if ('property_city' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_city:' . $term->term_id; . $anchor . '#here';
}
return $termlink;
}, 10, 3);
解决方案
您只需要在之后删除分号,
$term->term_id
最终代码将如下所示
add_filter('term_link', function ($termlink, $term, $taxonomy) {
if ('property_type' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_type:' . $term->term_id . $anchor . '#here';
}
if ('property_city' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine&tax=property_city:' . $term->term_id . $anchor . '#here';
}
return $termlink;
}, 10, 3);
推荐阅读
- javascript - 更改显示属性时,有序列表向左移动
- flutter - Flutter:无法使用 GradleUserHomeServices.createResourceSnapshotterCacheService() 创建 ResourceSnapshotterCacheService 类型的服务
- flutter - 如何将 context.read 传递给 Flutter 中的子小部件?潜在的 BuildContext 错误问题
- node.js - 快速会话不存在
- c# - 在 C# Winforms 中将数据添加到行 var xmlDocument
- html - 使用相机在手机上输入 HTML5 文件时要求 PNG,还是只能使用图像/jpeg?
- visual-studio - Microsoft.ReportViewer.WebForms.dll 两者都存在错误,如何解决这个问题?
- c# - Unity - 使两个完全相同的对象发生碰撞,但只有一个被删除
- java - android.content.Context.getResources() 在空对象引用上
- flutter - 颤振问题:ChangeNotifierProvider.value(value: Auth(),)