[英]Anchor is Being Modified by Current Page URL
In my site I am in the following page: 在我的网站上,我位于以下页面中:
mysite.com/especialidad/ensenanza/formacion-profesional/?region=alava
mysite.com/especialidad/ensenanza/formacion-profesional/?region=alava
The relevant part of the PHP template that contains that page is: 包含该页面的PHP模板的相关部分是:
<?php
/* Get the Queried Object */
$term = get_queried_object();
$enlace_especialidad = get_term_link( $term );
/* Get the Queried Object */
$user_query = new WP_User_Query(
array(
'meta_key' => 'especialidad_preparador',
'meta_value' => $term->term_id,
'number' => 100,
'meta_query' => $meta_query,
)
);
?>
<?php echo $enlace_especialidad; ?>
<h1 class="titulo_taxonomia">Preparadores de Oposiciones a <a href="<?php $enlace_especialidad ?>"><?php echo $term->name ?></a>
<?php
if ($_GET['region']) {
$taxonomia_region = get_term_by('slug', $_GET['region'], 'region');
echo 'en <a href="'. get_term_link( $taxonomia_region ) .'">'. $taxonomia_region->name .'</a>';
}
?>
When I echo the var $enlace_especialidad (just to check its value) the result is: 当我回显var $ enlace_especialidad(只是为了检查其值)时,结果是:
mysite.com/especialidad/ensenanza/formacion-profesional/
mysite.com/especialidad/ensenanza/formacion-profesional/
Instead, the part that refers to the URL: Preparadores de Oposiciones a <a href="<?php $enlace_especialidad ?>"><?php echo $term->name ?></a>
links to: 相反,引用URL的部分:Preparadores de Oposiciones的
<a href="<?php $enlace_especialidad ?>"><?php echo $term->name ?></a>
链接到:
mysite.com/especialidad/ensenanza/formacion-profesional/ ?region=alava
mysite.com/especialidad/ensenanza/formacion-profesional/?region = alava
The problem is that ?region=alava isn't in the var $enlace_especialidad, and I don't know how it appears when used in an anchor. 问题是?region = alava不在$ enlace_especialidad变量中,并且我不知道它在锚中使用时的外观。 On the other hand it is the current page URL, and I guess there must be a relation.
另一方面,它是当前页面的URL,我想一定是有关系的。
LAST EDIT 最后编辑
You forgot to echo before the link, so the anchor is void. 您忘记了在链接之前回显 ,因此锚点无效。 That's why you see incoherence with the printed output before.
这就是为什么您之前看到打印输出不一致的原因。
?region=alava
is here because it is a result of a $_GET
request with region as parameter. ?region=alava
在这里是因为它是将region作为参数的$_GET
请求的结果。 So it is in addition of your URL part. 因此,这是您URL部分的补充。
So your URL is just fine, the additionnal part is treated in this followed part : 因此,您的URL很好,下面的部分将处理附加部分:
<?php
if ($_GET['region']) {
$taxonomia_region = get_term_by('slug', $_GET['region'], 'region');
echo 'en <a href="'. get_term_link( $taxonomia_region ) .'">'. $taxonomia_region->name .'</a>';
}
?>
The part with get_term_link( $taxonomia_region )
contains the $_GET['region']
result part if it exist. 具有
get_term_link( $taxonomia_region )
包含$_GET['region']
结果部分(如果存在)。
See documentation of $_GET : http://php.net/manual/en/reserved.variables.get.php 请参阅$ _GET的文档 : http : //php.net/manual/zh/reserved.variables.get.php
EDIT 编辑
After our discussion in the comment, there's a difference with this method when you use different kind of parameter, ie get_term_link( $term );
在评论中我们进行讨论之后,当您使用不同类型的参数时,此方法会有所不同,即
get_term_link( $term );
or get_term_link( $taxonomia_region );
或
get_term_link( $taxonomia_region );
Since the term can be an object, integer, or string, make sure that any numbers you pass in are explicitly converted to an integer (example: (int) $term_id).
由于该术语可以是对象,整数或字符串,因此请确保将您传入的所有数字都显式转换为整数(例如:(int)$ term_id)。 Otherwise the function will assume that $term is a slug instead of a term ID.
否则,该函数将假定$ term是一个条目,而不是term ID。
That's why you get mysite.com/especialidad/ensenanza/formacion-profesional/
with get_term_link( $taxonomia_region );
这就是为什么使用
get_term_link( $taxonomia_region );
获得mysite.com/especialidad/ensenanza/formacion-profesional/
的原因get_term_link( $taxonomia_region );
because you pass a slug as parameter. 因为您将子弹作为参数传递。
And you get mysite.com/especialidad/ensenanza/formacion-profesional/?region=alava
with get_term_link( $term );
然后使用
get_term_link( $term );
获得mysite.com/especialidad/ensenanza/formacion-profesional/?region=alava
get_term_link( $term );
because you pass an object as parameter. 因为您将对象作为参数传递。
Source : https://developer.wordpress.org/reference/functions/get_term_link/ 来源 : https : //developer.wordpress.org/reference/functions/get_term_link/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.