[英]Wordpress - Load Custom Post Type on front-page.php
I'm looking to load a single custom post type as my homepage. 我希望加载一个自定义帖子类型作为我的主页。 Not an archive but a single post, ID 10190. Looking to do this without a redirect for SEO reasons.
不是存档,而是单个帖子,ID10190。出于SEO原因,希望在不进行重定向的情况下执行此操作。 What would be the simplest way to achieve this?
实现这一目标的最简单方法是什么?
Try this 尝试这个
add_action( 'template_redirect', 'so_48395149' );
function so_48395149() {
global $post;
if( is_front_page() ) {
$post = get_post( 10190 );
}
}
Note: I haven't tested this, but you'll be wanting something along these lines. 注意:我还没有测试过,但是您可能需要这些方面的帮助。
WordPress stores the currently viewed post in a global $post
variable. WordPress将当前查看的帖子存储在全局
$post
变量中。 In this case, we want to overwrite that with the specified post [type] only on the front page. 在这种情况下,我们只想在首页上使用指定的帖子[type]覆盖它。 We use the
template_redirect
hook as it's one of the last hooks available before the HTML is generated. 我们使用
template_redirect
钩子,因为它是生成HTML之前可用的最后一个钩子之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.