2009-12-18 77 views

回答

1

后的尝试和失败,几天一个很好的问题,我能够构建以下解决方案:

下面的代码添加到您的的header.php -file,位于的wp-content /主题/ nameOfTheme。确保没有空间或在开始前输入

<?php 
if(is_home()) { 
    $recentPosts = new WP_Query(); 
    $recentPosts->query('showposts=1'); 
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
    wp_redirect(get_permalink(), 301); 
    endwhile; 
} 
?> 
+0

301是“永久移动”的HTTP代码 - 这似乎不适合重定向到最近的帖子。您应该使用302 Found。 – akent 2016-01-12 00:13:20

0

使用.htaccess文件,并做做一个重定向的redirect

1

克里斯·霍姆斯的回答是一个很好的一个。

如果htaccess不是一个选项,或者你想在WordPress中完成,你可以使用is_home_page()和wp_redirect()将简单的逻辑添加到index.php中。 http://codex.wordpress.org/Function_Reference/is_home http://codex.wordpress.org/Function_Reference/wp_redirect

如果你是不是真的希望编程解决方案,我想这是https://superuser.com/ 也许,你正在寻找http://codex.wordpress.org/Creating_a_Static_Front_Page

相关问题