Saltar navegación

[Resuelto] Output Taxonomy Archive URL Inside an Archive

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to output the URL of the current taxonomy archive?

Solution:
You would need to register a custom shortcode, which does not need any attributes, simply returning the URL from the $_SERVER PHP object:

add_shortcode( 'current-url', function(){
 
    return $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
});
This support ticket is created hace 6 años, 2 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Thomas AMX hace 6 años, 2 meses.

Asistido por: Nigel.

Autor
Mensajes
#1130838

Hi Guys,

I am building lightweight, custom social sharing buttons and I would like to make taxonomy archive pages shareable. So, I need to generate the archive's URL and it turns out to to be unexpectedly tricky.

[wpv-taxonomy-url] seemed like an obvious choice at first, but it won't work inside taxonomy archives....
[wpv-taxonomy-archive info=""] works inside tax. loops, but doesn't have URLs as option... and using slugs won't work for hierchical taxonomies.

I found this shortcode written by Nigel:
https://toolset.com/forums/topic/displaying-view-by-taxonomies-url-in-the-archieve-loop/#post-1121600
It works but it also doesn't have URL as an option.

I have tried to 'reverse-engineer' it with : "if ($output = 'url')" and "get_term_link".
I suspect I was on the right track, but I don't really know PHP and so I have failed 🙂

Is it possible to adapt the shortcode so that it can output the archive's URL or perhaps there is another, simpler way to achieve it?

Cheers,
Tom

#1131862

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Tom

The archive URL isn't available with the query object used by the taxonomy shortcode you linked to, you should probably get it directly from the server request variables.

Try adding the following custom shortcode to output the current URL:

add_shortcode( 'current-url', function(){

    return $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

});
[php]

You can then use

[php]
[current-url]

to output the URL where required. You can manually include the protocol (e.g. enlace oculto) if you require it.

#1132984

Thank you very much, Nigel, it works!
What's cool about this code is that I would be able to use it in other contexts as well.
Excellent.

Cheers,
Tom