Come ottenere il percorso per il tema corrente?
2 risposta
- voti
-
- 2012-04-05
Penso che devi stare unpo 'attentoperché dipende da cosa stai cercando difare.
Se stai usando untemafiglio
get_template_directory();
andrà comunque altemaprincipale. Tuttaviaget_stylesheet_directory();
andrà altema,figlio ogenitore corrente. Inoltre,entrambe questefunzioni restituisconopercorsi server assoluti.Se desideri un URI completamenteformato,peri collegamenti o leimmagini,dovresti utilizzare
get_template_directory_uri();
oget_stylesheet_directory_uri();
utilizzando quello correttoperi motiviindicati .Riepilogo
-
get_stylesheet_directory()
:percorso delfile alla directory deltema corrente -
get_stylesheet_directory_uri()
:percorso URL della directory deltema corrente -
get_template_directory()
:percorso delfile alla directory deltemaprincipale -
get_template_directory_uri()
:percorso URL alla directory deltemaprincipale
I think you have to be a little careful because it depends on what you are trying to do.
If you are using a child theme
get_template_directory();
will still go to the parent theme. Howeverget_stylesheet_directory();
will go to the current theme, child or parent. Also, both these functions return absolute server paths.If you wanted a fully formed URI, for links or images, you should use
get_template_directory_uri();
orget_stylesheet_directory_uri();
using the correct one for the reasons stated.Summary
get_stylesheet_directory()
: file path to current Theme directoryget_stylesheet_directory_uri()
: url path to current Theme directoryget_template_directory()
: file path to parent Theme directoryget_template_directory_uri()
: url path to parent Theme directory
-
+1.* Usa sempre *percorsofile/url `stylesheet`perfare riferimento altema * corrente *e prenotapercorso/url`template`perfare riferimento altema *genitore *.+1. *Always* use `stylesheet` filepath/url to reference the *current* Theme, and reserve `template` filepath/url to reference the *parent* Theme.
- 3
- 2012-04-05
- Chip Bennett
-
Sfortunatamenteget_template_directory () restituisce l'interopercorso del server come `/var/www/the/path/of/actual/wp-content/themes/mytheme` chenon è quello che vuoiperfare cose con $ wp_filesystem se WP si connettetramite FTP.Unfortunately get_template_directory() returns the entire server path like `/var/www/the/path/of/actual/wp-content/themes/mytheme` which is not what you want for doing stuff with $wp_filesystem if WP is connecting through FTP.
- 0
- 2014-09-11
- NoBugs
-
@NoBugs - Stavo ottenendo anche l'interopercorso del server,ma l'uso diget_stylesheet_directory_uri ()invece diget_stylesheet_directory () ha risoltoilproblema.@NoBugs - I was getting the entire server path as well but using get_stylesheet_directory_uri() instead of get_stylesheet_directory() solved the issue.
- 0
- 2015-02-04
- TheLibzter
-
Grazie!lamaggiorparte delle risposte che hotrovatomi haportatoin parte usandoget_stylesheet_directory (),mapoi sono rimastonella directoryprincipale delmio server.get_stylesheet_directory_uri () è stata la risposta allemie preghiere!Thank you! most answers i found got me part of the way there with using get_stylesheet_directory() but then I was left in the root directory of my server. get_stylesheet_directory_uri() was the answer to my prayers!
- 0
- 2020-08-07
- sigmapi13
-
- 2012-04-05
get_stylesheet_directory_uri
è quello che vuoi. restituisce l'URL deltema corrente.get_stylesheet_directory
restituiràilpercorso delfile sul server.Adesempio:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/image.png" />
Se haibisogno deltemaprincipale,
get_template_directory
eget_template_directory_uri
sonogliequivalenti.Senon èpresente alcuntemaprincipale,entrambi restituiranno lo stesso valore.
Ulteriore lettura:
-
get_stylesheet_directory
- percorso della cartella assoluto deltema corrente
- ades.
/var/www/yoursite/wp-content/themes/child_theme
-
get_template_directory
- percorso cartella assoluto deltemaprincipale
- ades.
/var/www/yoursite/wp-content/themes/parent_theme
-
get_stylesheet_directory_uri
- URL completo deltema corrente
- ades.
https://example.com/wp-content/themes/child_theme
-
get_template_directory_uri
- URL completo deltemaprincipale
- ades.
https://example.com/wp-content/themes/parent_theme
get_stylesheet_directory_uri
is what you want. it returns the URL of the current theme.get_stylesheet_directory
will return the file path on the server.For example:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/image.png" />
If you need the parent theme,
get_template_directory
andget_template_directory_uri
are the equivalents.If there is no parent theme then both will return the same value.
Further reading:
get_stylesheet_directory
- absolute folder path of current theme
- e.g.
/var/www/yoursite/wp-content/themes/child_theme
get_template_directory
- absolute folder path of parent theme
- e.g.
/var/www/yoursite/wp-content/themes/parent_theme
get_stylesheet_directory_uri
- full URL of current theme
- e.g.
https://example.com/wp-content/themes/child_theme
get_template_directory_uri
- full URL of parent theme
- e.g.
https://example.com/wp-content/themes/parent_theme
-
`get_stylesheet_directory ()` è la risposta corretta.`get_template_directory ()`punterà altemaprincipale se viene utilizzato untemafiglio.`get_stylesheet_directory()` is the correct answer. `get_template_directory()` will point to the parent theme if a child theme is being used.
- 0
- 2020-07-11
- Lucas Bustamante
-
Ho adattato la risposta di conseguenzaI adjusted the answer accordingly
- 0
- 2020-08-25
- Tom J Nowell
Questo codice viene utilizzatoper ottenere la directory delplugin corrente:
plugin_dir_url( __FILE__ )
.Cosa devo usareper ottenere la directory deltema corrente?