Pourquoi is_home () ne fonctionne-t-il pas correctement?
-
-
Mercipour lestags!Thanx for tags!
- 0
- 2010-08-23
- naugtur
-
2 réponses
- votes
-
- 2010-08-19
is_home()
ne fonctionnerapastant quewp_query
ne serapasexécuté.Lepremier hook que vouspouvez utiliser oùis_homefonctionneraest'parse_query'
,mais'template_redirect'
seraitmieux.is_home()
won't work untilwp_query
is run. The earliest hook you can use where is_home will work is'parse_query'
, but'template_redirect'
would be better.-
Techniquement,``parse_query '' s'exécute avant `` wp ''et est lepremier absolu que vouspouvez vérifierpour `is_home ()` avec une quelconque certitude.Technically, `'parse_query'` runs before `'wp'` and is the absolute earliest you can check for `is_home()` with any certainty.
- 0
- 2010-08-19
- John P Bloch
-
wp ()est appelé aprèsinit,donctemplate_redirectest lepremier hook,pourplus d'optionset unemeilleure vue,voir: http://toolpress.de/Toolpress_-_Wordpress-3.0-Program-Flow-0.2-2010-06-28.pdfwp() is called after init, so template_redirect is the first hook, for more options and a better view, see: http://toolpress.de/Toolpress_-_Wordpress-3.0-Program-Flow-0.2-2010-06-28.pdf
- 0
- 2010-08-19
- hakre
-
Vousm'avezmal compris,hakre.``parse_query ''et `` wp '' sont également des hooks d'action,et c'est ce à quoije faisais référence.You misunderstood me, hakre. `'parse_query'` and `'wp'` are action hooks too, and that's what I was referencing.
- 0
- 2010-08-19
- John P Bloch
-
ohnon,pas dutout.Je voulaisjuste souligner ce que vous avez écrit.Jepense que votre réponseesttout àfaitjuste.oh, no, not at all. I just wanted to underline what you wrote. I think your answer is just totally right.
- 0
- 2010-08-20
- hakre
-
- 2010-08-19
Pour donner suite à la réponse de John: Ajoutez un appel à laditefonction sur l'un des hooksmentionnéspar Johnet Hakre.
Ajoutez,parexemple,ce qui suit à votrefunctions.php:
<?php function my_function_name(){ if(is_home()) do_something(); } add_action('template_redirect', 'my_function_name'); ?>
EDIT: J'aimal lu votre question au début -il semble que vous ayez déjà unefonctionencapsulant le code,c'estjuste que voustirez sur lemauvais crochet.Soit divisez cette sectionen unefonction distincteet faites-la déclencher surtemplate_redirect,etc.,soit changez l'endroit où vous vous connectezen premier lieu.
To follow up on John's answer: Add a call to said function on one of the hooks mentioned by John and hakre.
Add, e.g., the following to your functions.php:
<?php function my_function_name(){ if(is_home()) do_something(); } add_action('template_redirect', 'my_function_name'); ?>
EDIT: I misread your question at first -- it looks like you've got a function encapsulating the code already, it's just that you're firing on the wrong hook. Either break that section out into a separate function and have it fire at template_redirect, etc., or change where you're hooking in the first place.
J'aimis unbit
if(is_home())
dans lefunctions.php demonthèmeet celane semblepasfonctionner.Lafonction contenant cebit est appelée surinit,doncis_home
devrait déjàfonctionner.