Php Wordpress根/sage主题模板CPT单页
我正在为一个项目使用wordpress的roots/sage主题模板。 我有一个名为“tour”的CPT,想为它创建一个单独的页面。在sage提供的文件中,我看到一个single.php如下所示:Php Wordpress根/sage主题模板CPT单页,php,html,wordpress,Php,Html,Wordpress,我正在为一个项目使用wordpress的roots/sage主题模板。 我有一个名为“tour”的CPT,想为它创建一个单独的页面。在sage提供的文件中,我看到一个single.php如下所示: <?php get_template_part('templates/content-single', get_post_type()); ?> 我在内容单页中看到一个峰值,然后看到: <?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/content-single', get_post_type()); ?>
我在内容单页中看到一个峰值,然后看到:
<?php while (have_posts()) : the_post(); ?>
<article <?php post_class(); ?>>
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_template_part('templates/entry-meta'); ?>
</header>
<div class="entry-content">
<?php the_content(); ?>
</div>
<footer>
<?php wp_link_pages(['before' => '<nav class="page-nav"><p>' . __('Pages:', 'sage'), 'after' => '</p></nav>']); ?>
</footer>
<?php comments_template('/templates/comments.php'); ?>
</article>
<?php endwhile; ?>
您可能希望签出WordPress模板层次结构
自定义帖子类型使用以下路径呈现适当的
存档索引页
存档-{post_type}.php
archive.php
index.php
如果您的自定义帖子类型是public,您可以通过访问{your url}/{custom post type slug}存档页面将加载模板/content-cpt.php来访问帖子
单个页面将加载模板/content-Single-cpt.php
其中“cpt”是您的自定义帖子类型名称(此处为“tour”)
templates/content-tour.php和templates/content-single-tour.php,这将起作用。设置帖子类型后,还应转到WordPress后端中的设置>永久链接,然后按保存更改。这似乎更新了系统,使新的post类型的slug工作 嘿,Josh,附带问题:您是否将此模板(在主要问题之后)archive-tour.php添加到templates文件夹中?或者将其放在模板目录的根目录中?在目录的根目录中,模板用于您自己的部分,这些部分不订阅默认的WordPress模板层次结构。虽然我相信计划是在Sage 9版本中改变这一点。好的,谢谢你的反应。我是这样做的:复制template-custom.php文件,并根据需要对其进行重命名。然后在templates文件夹中创建一个新文件。可惜没有;这不是最佳实践指南!