当前位置: 首页 > 知识库问答 >
问题:

WordPress单自定义帖子类型模板

纪辰沛
2023-03-14

我试图为自定义帖子类型创建一个页面,但我无法真正实现。以下是我正在尝试的全部内容-

自定义帖子类型注册的functions.php片段

<?php
function custom_post_type() {

$labels = array(
    'name'                => _x( 'Tutorials', 'Post Type General Name', 'text_domain' ),
    'singular_name'       => _x( 'Tutorial', 'Post Type Singular Name', 'text_domain' ),
    'menu_name'           => __( 'Tutorial', 'text_domain' ),
    'parent_item_colon'   => __( 'Parent Tutorial:', 'text_domain' ),
    'all_items'           => __( 'All Tutorials', 'text_domain' ),
    'view_item'           => __( 'View Tutorial', 'text_domain' ),
    'add_new_item'        => __( 'Add New Tutorial', 'text_domain' ),
    'add_new'             => __( 'New Tutorial', 'text_domain' ),
    'edit_item'           => __( 'Edit Tutorial', 'text_domain' ),
    'update_item'         => __( 'Update Tutorial', 'text_domain' ),
    'search_items'        => __( 'Search Tutorials', 'text_domain' ),
    'not_found'           => __( 'No Tutorials found', 'text_domain' ),
    'not_found_in_trash'  => __( 'No Tutorials found in Trash', 'text_domain' ),
);
$args = array(
    'label'               => __( 'Tutorial', 'text_domain' ),
    'description'         => __( 'Tutorial information pages', 'text_domain' ),
    'labels'              => $labels,
    'supports'            => array('title','editor','author','excerpt','custom-fields'),
    'taxonomies'          => array( 'category', 'post_tag' ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);
register_post_type( 'Tutorial', $args );
}
add_action( 'init', 'custom_post_type' ); ?>

我使用名为单Tutorial.php的模板为这个自定义帖子类型模板。此外,在我的帖子显示中,我使用the_permalink()链接到帖子。

现在考虑一个标题为Test3的帖子现在在我的仪表板上,我看到它的PyMalink AS。

http://localhost/deadman/portfolio/tutorial/test3/

当我回显我得到的_permalink的内容时-

http://localhost/deadman/portfolio/tutorial/test3/ 

现在虽然他们指向同一个地方,但我仍然被重定向到主页,而不是单一的帖子类型页面

共有1个答案

左丘善
2023-03-14

自定义帖子的名称不能包含大写字母,所以将register_post_type('Tut指南',$args);更改为register_post_type('教程',$args);

此外,模板文件应该是single-tutorial.php而不是单Tutorial.php

最后,您必须保存永久链接设置以刷新新闻url。这是需要的,因为wordpress缓存重写规则,并且当您创建自定义post wordpress时,不会自动刷新新的重写规则。

有用链接:

http://wp-bytes.com/function/2013/02/flushing-permalinks/

http://codex.wordpress.org/Rewrite_API/flush_rules

 类似资料:
  • 本文向大家介绍WordPress 注册自定义帖子类型,包括了WordPress 注册自定义帖子类型的使用技巧和注意事项,需要的朋友参考一下 示例 假设您有一个图书馆网站,并且想要一个名为Books的自定义帖子类型。可以注册为 如此简单,您现在就注册了一个自定义帖子类型。 该代码段可以放在主题functions.php文件中,也可以放在插件结构中。

  • 本文向大家介绍WordPress 3.0中的自定义帖子类型,包括了WordPress 3.0中的自定义帖子类型的使用技巧和注意事项,需要的朋友参考一下 本文与WordPress 3.0相关。此处发布的许多代码在以前的版本中将不起作用,并且某些信息可能会在较新的版本中更改。 WordPress已经在系统中内置了五种不同的内容类型。 帖子 这是标准的内容类型,通常是博客安装中使用最多的内容。帖子往往会

  • 我已经使用代码设置了WordPress自定义帖子类型。我已经设法让自定义帖子显示在“归档”页面中,但如果我单击“归档”页面中的链接,WP无法找到单个帖子页面。 我想我可能对定制的post permalinks有问题。希望有人能帮我 functions.php 页面模板 要显示自定义帖子,我设置了一个带有WP查询的新页面模板: 页面模板代码似乎工作和所有自定义帖子显示预期但当我点击标题链接我得到一个

  • 我创建了一个名为制造商的自定义帖子类型,并添加了大量帖子和类别。单个帖子页面工作,但类别/存档页面不显示任何帖子。 制造商被分成不同的类别,我需要显示每个类别中所有帖子的存档。我去工厂的时候 http://localhost/category/manufactures/ge-speedtronic/ 这就是令人困惑的地方。我为自定义帖子类型“制造商”使用的类别也显示在我的其他自定义帖子类型和默认帖

  • 我对Magento很陌生。我想在Magento中输入WordPress post和自定义post类型。为此,我安装了Magento WordPress集成扩展。我成功地从WordPress中获取帖子,我在Magento根目录中安装了WordPress,使用的数据库与Magento使用的数据库相同。对于自定义帖子类型,我还购买了帖子类型 现在,我的问题是,如何将自定义帖子类型从WordPress导入

  • 我是WordPress的新手,我正在尝试将纯HTML主题转换为WordPress主题。但我有一个问题,我找不到解决办法。在nav菜单中,我找不到有选择地向WordPress作为菜单生成的和元素添加类的方法。 基本上,我需要为1个深度元素、2个深度元素和3个深度元素设置不同的类,还需要检查项目是否有子元素,然后还需要设置不同的类。 然后,我必须将onhtml脚本放在元素中(我知道这些是按钮,但我认为