我可以从插件目录加载单页吗?

发布于 2025-02-03 01:46:56 字数 266 浏览 2 评论 0原文

作为WP插件开发人员,我想从插件目录加载一个帖子单页。不是自定义帖子类型我想从默认的wp post类型加载。 function.php < < a href =“ https://i.sstatic.net/dslth.png” rel =“ nofollow noreferrer”> template.php

As a wp plugin developer, I want to load a post single page from my plugin directory. Not a custom post type I want to load from the default wp post type.function.php template.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心荒芜 2025-02-10 01:46:56

您可以使用此挂钩检查这是否是单页,并且帖子类型为“帖子”

add_action( 'single_template', [$this, 'event_single_page'] );
function event_single_page( $single ) {
        global $post;
        if ( $post->post_type == 'post' &&  is_singular( 'post' ) ) {
            $plugin_template = 'post-single-page.php';
            if ( file_exists( $plugin_template ) ) {
                $single = $plugin_template ;
            }
        }
        return $single;
    }

You can use this hook to check if this is a single page and the post type is 'post'

add_action( 'single_template', [$this, 'event_single_page'] );
function event_single_page( $single ) {
        global $post;
        if ( $post->post_type == 'post' &&  is_singular( 'post' ) ) {
            $plugin_template = 'post-single-page.php';
            if ( file_exists( $plugin_template ) ) {
                $single = $plugin_template ;
            }
        }
        return $single;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文