所以我开始写一个Wordpress主题,我试图将我的index.php
中的The Loop
的一些变量传递给content.php
中的实际内容呈现器。
由于范围问题,我不能只在index.php
中创建一个变量,然后尝试在content.php
中访问它。使用global
的想法让我感到不寒而栗,所以我想也许我会把它加到$post
变量上(这已经是全球性的)。这是一种标准做法吗?除了意外修改标准$post
成员var之外,是否有任何理由不希望这样做?有没有一种惯用的WordPress的方式来做到这一点?
这是我index.php
的例子:
$post->is_n = false; # bad idea?
if($post_number === $n){
$post->is_n = true
}
get_template_part('content', get_post_format());
在
然后我content.php
:
if($post->is_n){$article_classes .= " is-n";}
谢谢,我会研究一种不同的方法。 – Soup 2012-04-29 06:04:59