开发者

Use first post as start-page in WordPress

开发者 https://www.devze.com 2022-12-14 20:42 出处:网络
Is there an easy way to redirect the user to the first post when they go to the开发者_运维问答 WordPress installation\'s main URL... Like, if the user goes to domain.com, they will be redirected to do

Is there an easy way to redirect the user to the first post when they go to the开发者_运维问答 WordPress installation's main URL... Like, if the user goes to domain.com, they will be redirected to domain.com/title-of-the-first-post..


After a few days of trying and failing, I was able to construct the following solution:

Add the following code to your header.php-file, located in wp-content/themes/nameOfTheme. Make sure there is no space or enter before the opening

<?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;
}
?>


Chris Holmes answer of doing a redirect is a good one.

If htaccess is not an option, or you want to do it within WordPress, you can add simple logic to index.php using is_home_page(), and wp_redirect(). http://codex.wordpress.org/Function_Reference/is_home http://codex.wordpress.org/Function_Reference/wp_redirect

If you are not really looking to program a solution, I imagine this is a good question for https://superuser.com/ Maybe, you are looking for http://codex.wordpress.org/Creating_a_Static_Front_Page


Use your .htaccess file and do a redirect

0

精彩评论

暂无评论...
验证码 换一张
取 消