【发布时间】:2011-12-31 06:07:08
【问题描述】:
我想将我的 wordpress 博客的访问者重定向到 latest single post。
我找不到插件,也不知道怎么做!
例如www.example.com --> www.example.com/?p=123
【问题讨论】:
标签: php wordpress plugins redirect
我想将我的 wordpress 博客的访问者重定向到 latest single post。
我找不到插件,也不知道怎么做!
例如www.example.com --> www.example.com/?p=123
【问题讨论】:
标签: php wordpress plugins redirect
快速google search 将帮助您。
将此代码放在index.php 或主页顶部,get_header() 函数上方。
<?php
/*
index.php (Blog Home Page):
Redirect To First Post
*/
if (have_posts()) {
while (have_posts()) {
the_post();
wp_redirect(get_permalink());
}
}
?>
【讨论】:
www.example.com/?product=432
您是否尝试过从 WP 内容表中选择 MAXID,然后在您的重定向中使用该 ID,这将是最新的帖子。
或者
我相信 wordpress 中有一个设置可以使主页成为最新帖子。
【讨论】:
add_action('wp_head','hook_css');
function hook_css() {
if( is_front_page() ) {
$latest = get_posts( "post_type=post&numberposts=1" );
$permalink = get_permalink( $latest[0]->ID );
$output="<meta http-equiv='refresh' content='4;url=" . $permalink . "'/>";
echo $output;
}}
【讨论】: