如何仅在主页上添加新闻自动收报机

时间:2013-12-20 10:19:37

标签: php wordpress wordpress-plugin

我安装了新闻自动收报机插件

然后我在sidebar.php中添加了必要的功能/代码

<!-- BEGIN: #secondary -->
<div id="secondary" class="g1-sidebar widget-area" role="complementary">
<h3>Latest News</h3>
<div id="news">
<?php if ( function_exists('insert_newsticker') ) { insert_newsticker(); } ?>
</div>
.......
.........
</div>

现在新闻自动收报机出现在所有页面的侧边栏上。

但我希望它只添加主页sideabr。

有没有办法做到这一点,所以如果侧栏是主要/家庭

然后才显示新闻自动收报机......

3 个答案:

答案 0 :(得分:1)

使用is_front_page()进行首页检查。

if( is_front_page() && function_exists('insert_newsticker') ){
    insert_newsticker();
}

更多信息is_front_page()

根据评论更新:

<div id="secondary" class="g1-sidebar widget-area" role="complementary">
<?php if( is_front_page() ): ?>
// Your h3 tag here
<?php endif; ?>
<h3>Latest News</h3>
<div id="news">

答案 1 :(得分:0)

答案 2 :(得分:0)

$ _SERVER [“REQUEST_URI]将包含当前地址的uri,因此如果将其与主页(”/“)进行比较,它将允许您查看是否插入它。您还可以相当轻松地添加对如果您决定稍后在其中添加插件,则会在您网站上显示其他页面。

相关问题