我有一个名为“主页”的页面,这是我的网站的正面设置,但我希望它显示最新的博客帖子在底部一两个。我有一些PHP可以从另一个站点执行此操作
<?php
query_posts('showposts=1');
while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content('Read the rest of this entry »'); ?>
<p><a href="<?php echo $siteroot .'/blog/' ?>">Go to the Blog...</a></p>
<?php endwhile; ?>但是我不知道要把它放在哪里,所以它只显示在这个特定的页面上,因为is_home()返回页面的false。
发布于 2012-07-02 02:30:46
既然您说的是“页面”,我认为您应该尝试is_page而不是is_home:
<?php
if ( is_page( 'about' ) ) {
// Code to be shown on Page whose slug is "about"
}
?>或者就代码的方式而言,这应该可以做到:
<?php if ( is_page( 'about' ) ) { ?>
<!-- Code to be shown on Page whose slug is "about" -->
<?php } ?>发布于 2012-07-02 03:39:45
您可以使用'is_front_page‘而不是'is_home’在设置为站点首页的页面上显示代码。任何设置为“设置->阅读->首页显示”下的首页将显示查询中的内容,而不是依赖特定的页面片段。
http://codex.wordpress.org/Function_参考/is_前面_页面
https://wordpress.stackexchange.com/questions/57144
复制相似问题