如何在 WordPress 中显示自定义帖子类型下拉模板的不同标题

发布于 2025-01-10 23:08:32 字数 606 浏览 1 评论 0原文

我有一个名为 cme-education 的自定义帖子类型,它有一个下拉菜单,用于选择自定义帖子类型模板(与 WordPress 中页面的页面模板下拉菜单类似)。当我选择模板时,它可以工作,但是我希望能够显示该模板的不同标题,但我不确定如何实现这一点。

我的下拉 CPT 模板代码位于 template-in-conversation.php 文件

<?php
/*
 Template Name: IN CONVERSATION 
 Template Post Type: cme-education
*/
?>

<?php get_header(); ?>

,然后我有一个头文件,其中有一个 if 语句来根据条件显示关联的头 header.php 文件

 if(is_singular('in-conversation')){
        get_template_part('includes/headers/header_in_convo'); 
    } else {
        echo "not found";
    }

I have a Custom post type called cme-education which has a drop down to select a custom post type template (similarly how you would with a page template drop down for pages in wordpress). When I select the template, it works however, I want to be able to show a different header for that template but I am not sure how to achieve that.

my code for the drop down CPT template is in
template-in-conversation.php file

<?php
/*
 Template Name: IN CONVERSATION 
 Template Post Type: cme-education
*/
?>

<?php get_header(); ?>

and then I have a header file which has an if statement to show the associated headers based on the condition
header.php file

 if(is_singular('in-conversation')){
        get_template_part('includes/headers/header_in_convo'); 
    } else {
        echo "not found";
    }

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

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

发布评论

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

评论(1

愁杀 2025-01-17 23:08:33

您需要为此添加一个自定义头文件,例如 header-in_convo.php

然后你可以这样做:

if(is_singular('in-conversation')){
    get_header( 'in_convo' );
} else {
    echo "not found";
}

请参阅此处

You need to add a custom header file for that like header-in_convo.php.

Then you could do this:

if(is_singular('in-conversation')){
    get_header( 'in_convo' );
} else {
    echo "not found";
}

See here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文