我想添加文本,但只显示在主页上。我使用了以下if脚本:
<?php if( is_home() ) : ?>
<p>Some text</p>
<?php endif;?>
但问题是它出现在每个分页的页面上。例如,如果我查看http://www.example.com/page/2/
它将显示该文本。我只希望它出现在第一页。有什么办法吗?
我想添加文本,但只显示在主页上。我使用了以下if脚本:
<?php if( is_home() ) : ?>
<p>Some text</p>
<?php endif;?>
但问题是它出现在每个分页的页面上。例如,如果我查看http://www.example.com/page/2/
它将显示该文本。我只希望它出现在第一页。有什么办法吗?
您可以使用is_paged()
。。。检查显示的页面是否已“分页”,当前页码是否大于1。这是一个布尔函数,意味着它返回TRUE或FALSE。
您可以按如下方式调整代码
<?php if( is_home() && !is_paged() ) : ?>
<p>Some text</p>
<?php endif;?>
还有一种方法可以在所有页面和类别中显示文本块,但在主页上隐藏它,反之亦然。
<?php if( is_front_page() =="" ) : ?>
<p>Some text here</p>
<?php endif;?>
我有以下循环(这是在single 页面,而不是index.php):$top_meta_cat_args = array( \'posts_per_page\' => 9, \'post_type\' => \'post\', \'meta_key\' => \'top-radio\', \'meta_value\' => \'top-yes\', \'post_status\' =&g