我的索引页如下所示。。。
<div id="ad-id">google ad code goes here </div><br />
<div id="post-id">My posts are goes here</div>
我使用 get_template_part(\'index\')
在另一个页面模板中。但我只想要索引的帖子,而不是谷歌的广告。帮帮我。。
提前感谢……)
我的索引页如下所示。。。
<div id="ad-id">google ad code goes here </div><br />
<div id="post-id">My posts are goes here</div>
我使用 get_template_part(\'index\')
在另一个页面模板中。但我只想要索引的帖子,而不是谷歌的广告。帮帮我。。
提前感谢……)
在您的index
模板,您将希望在您的谷歌广告周围添加一个条件。该条件的主题由您决定,并将取决于您的确切需求。例如,如果您希望它显示在主页上,但不显示在其他页面上,您可以检查is_home()
. 如果您的需求更抽象,您可以定义一个全局变量,并在get_template_part
呼叫,例如。$GLOBALS[\'show_ad\'] = true;
然后只显示谷歌广告,如果这是真的。
<?php if ( is_home() ) : ?>
<div id="ad-id">google ad code goes here </div><br />
<?php endif ?>
<div id="post-id">My posts are goes here</div>
或者,说你的需求更抽象。这两个页面都有一个全局变量。index page:
<?php if ( isset( $GLOBALS[\'show_ad\'] ) && true == $GLOBALS[\'show_ad\'] ) : ?>
<div id="ad-id">google ad code goes here </div><br />
<?php endif ?>
<div id="post-id">My posts are goes here</div>
Calling template:
# Show the ad
$GLOBALS[\'show_ad\'] = true;
get_template_part( \'index\' );
。。。或# Don\'t show the ad
$GLOBALS[\'show_ad\'] = false;
get_template_part( \'index\' );
是否可以更改主页,使其不是博客,而是页面?还有,是否可以更改主页的名称?如果是,如何做到这一点?谢谢Richard