[英]Wordpress roots/sage theme template single page for CPT
I am using roots/sage theme template for wordpress for a project.我正在为一个项目的 wordpress 使用 root/sage 主题模板。 I have a CPT named "tour" and want to create a single page for it.
我有一个名为“tour”的 CPT,想为它创建一个页面。 I see in the files provided by sage a single.php that looks like this:
我在 sage 提供的文件中看到一个 single.php 看起来像这样:
<?php get_template_part('templates/content-single', get_post_type()); ?>
I go take a peak in the content-single page and see this:我在 content-single 页面中找到了一个高峰,看到了这个:
<?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; ?>
I'm thinking okay this is just an example so I remove everything from the content-single.php and place a <h1>hello</h1>
我想这只是一个例子,所以我从 content-single.php 中删除所有内容并放置一个
<h1>hello</h1>
I go take a look at my CPT single page and get an error "page not found" anyone knows what I'm doing wrong here?我去看看我的 CPT 单页并收到错误“找不到页面”有人知道我在这里做错了什么吗?
Archive pages will load templates/content-cpt.php Single pages will load templates/content-single-cpt.php存档页面将加载模板/content-cpt.php 单个页面将加载模板/content-single-cpt.php
Where "cpt" is your custom post type name ("tour" here ).So create templates/content-tour.php and templates/content-single-tour.php and that will work .其中“cpt”是您的自定义帖子类型名称(此处为“tour”)。因此,创建 templates/content-tour.php 和 templates/content-single-tour.php 就可以了。
You may want to check out the WordPress template hierarchy.您可能想查看 WordPress 模板层次结构。
Custom Post Types use the following path to render the appropriate archive index page.
自定义帖子类型使用以下路径来呈现适当的存档索引页面。
- archive-{post_type}.php
存档-{post_type}.php
- archive.php
档案.php
- index.php
索引.php
If your custom post type is public, you'll be able to access the posts by visiting {your-url}/{custom-post-type-slug}如果您的自定义帖子类型是公开的,您将能够通过访问 {your-url}/{custom-post-type-slug} 来访问这些帖子
After you set up a post type you should also go to Settings > Permalinks in the the WordPress back-end and press Save Changes.设置帖子类型后,您还应该转到 WordPress 后端中的设置 > 永久链接,然后按保存更改。 This seems to update the system so that the new post type's slug works.
这似乎更新了系统,以便新帖子类型的 slug 工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.