Wordpress 单帖子类型模板不显示帖子

     2023-03-06     162

关键词:

【中文标题】Wordpress 单帖子类型模板不显示帖子【英文标题】:Wordpress single-post-type template not displaying post 【发布时间】:2013-05-06 16:54:15 【问题描述】:

我有一个包含两种自定义帖子类型、布道和成员的主题。我还将永久链接设置为 postname。

一开始,single.php 会捕捉一般的博客文章,以及成员,但不会捕捉布道……它只会显示 index.php 文件。

经过一些研究,我发现重置(保存)永久链接会重置它们。这种工作现在捕获成员自定义帖子,但仅显示 index.php 用于布道。

我就是这样称呼他们的……

// Custom Post types for Sermons
add_action('init', 'sermons');

function sermons() 
  $args = array(
    'labels' => array(
       'name' => __( 'Sermons' ),
       'singular_name' => __( 'Sermons' ),
       'add_new' => __( 'Add Sermon' ),
       'add_new_item' => __( 'Add Sermon' ),
       'edit_item' => __( 'Edit Sermon' ),
       'new_item' => __( 'Add Sermon' ),
       'view_item' => __( 'View Sermon' ),
       'search_items' => __( 'Search Sermons' ),
       'not_found' => __( 'No Home Sermons found' ),
       'not_found_in_trash' => __( 'No Sermons found in trash' )
   ),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    // 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
    'rewrite' => true,
    'exclude_from_search' => true,
    'menu_position' => 20,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'has_archive' => true
  );

  register_post_type('sermons',$args);


// Custom Post types for Members
add_action('init', 'members');

function members() 
  $args = array(
    'labels' => array(
       'name' => __( 'Members' ),
       'singular_name' => __( 'Members' ),
       'add_new' => __( 'Add Member' ),
       'add_new_item' => __( 'Add Member' ),
       'edit_item' => __( 'Edit Member' ),
       'new_item' => __( 'Add Member' ),
       'view_item' => __( 'View Member' ),
       'search_items' => __( 'Search Members' ),
       'not_found' => __( 'No Home Members found' ),
       'not_found_in_trash' => __( 'No Members found in trash' )
   ),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    // 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
    'rewrite' => true,
    'exclude_from_search' => true,
    'menu_position' => 20,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'has_archive' => true
  );

  register_post_type('members',$args);

我试过single-sermons.php 和single-members.php,似乎都不管用。是我注册每种自定义帖子类型的方式破坏了这一点吗?

**** 编辑 **** 从 $args 中删除了 'rewrite' => true,一切都很好,但我更希望有 SEO 友好的网址。

**** 编辑 **** 修复它...显然,删除 args 中的 'rewrite' => true,刷新永久链接,然后再次添加 'rewrite' => true,就成功了。

【问题讨论】:

只是想知道将 'publicly_queryable' => true 设置为参数是否有帮助。 codex.wordpress.org/Function_Reference/… 。如果设置 single-sermons.php 和 single-members.php 模板怎么样? 是的,试过了。由于某种原因它不会渲染。我会尝试你的建议。非常感谢 【参考方案1】:

您应该在创建自定义帖子类型后执行flush_rewrite_rules(),这将为您刷新永久链接结构。

只需在 register_post_type() 函数后添加 flush_rewrite_rules()

更多信息:http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

【讨论】:

它起作用了,按照它应该做的。但它也让我回到了原来的问题。 我怀疑您遇到的问题出在上面的代码中,我没有发现任何异常【参考方案2】:

修复它...显然,删除参数中的'rewrite' => true,刷新永久链接,然后再次添加'rewrite' => true,就可以了。

【讨论】:

【参考方案3】:

重新保存永久链接对我有用。 (设置 -> 永久链接 -> 保存)。

【讨论】:

我在问题中提到保存永久链接并不能完全解决问题。玛丽路易斯帕克密码?? 我知道,但删除 'rewrite' => true 对我不起作用,因此永久链接修复可能适用于具有相同情况的其他人。干杯【参考方案4】:

设置publicly_queryable => true 解决了我的问题。

【讨论】:

在 wordpress 的自定义页面模板中显示帖子分类信息

】在wordpress的自定义页面模板中显示帖子分类信息【英文标题】:Showposttaxonomyinformationincustompagetemplateinwordpress【发布时间】:2017-11-2510:08:41【问题描述】:我有一个正在通过子主题编辑的主题。我已经能够创建自定义页面模板... 查看详情

WordPress自定义帖子页面不显示

】WordPress自定义帖子页面不显示【英文标题】:WordPressCustomPostsPageNotDisplaying【发布时间】:2018-09-2215:47:28【问题描述】:我刚刚在WordPress中遇到了一个小而奇怪的问题。我创建了一个名为“nyheter”的页面(翻译成挪威语的新闻... 查看详情

Wordpress 按帖子类型订购帖子

】Wordpress按帖子类型订购帖子【英文标题】:Wordpressorderpostsbyposttype【发布时间】:2013-03-1812:06:57【问题描述】:我正在尝试创建一个从2种帖子类型中获取帖子的系统,并且我想按帖子类型显示帖子顺序。我试图首先显示来自一... 查看详情

php自定义帖子类型模板wordpress(代码片段)

查看详情

Wordpress 为自定义帖子类型存档页面选择了错误的模板

】Wordpress为自定义帖子类型存档页面选择了错误的模板【英文标题】:WordpressPicksUpWrongTemplateforCustomPostTypeArchivePage【发布时间】:2017-11-2111:31:28【问题描述】:我已经注册了以下两种自定义帖子类型:functiondogs()$labels=array(\'name\'... 查看详情

如何在 wordpress 中显示自定义帖子类型类别?

】如何在wordpress中显示自定义帖子类型类别?【英文标题】:Howtodisplaycustomposttypecategoryinwordpress?【发布时间】:2014-04-1416:13:21【问题描述】:最近我在wordpress中创建了一个自定义帖子类型,并添加了名为category和tags的分类法。... 查看详情

按自定义分类类型迭代自定义帖子类型? (按类别排序 wordpress 帖子,或按分类术语显示自定义帖子类型)

】按自定义分类类型迭代自定义帖子类型?(按类别排序wordpress帖子,或按分类术语显示自定义帖子类型)【英文标题】:Iteratethroughcustomposttypebycustomtaxonomytype?(Orderingwordpresspostsbycategory,ordisplayingcustomposttypebytaxonomyterm)【发布时... 查看详情

在 WordPress 管理列帖子/产品自定义帖子类型中显示 Slug

】在WordPress管理列帖子/产品自定义帖子类型中显示Slug【英文标题】:DisplaySluginWordPressAdminColumnsposts/productscustomposttype【发布时间】:2013-01-1912:22:27【问题描述】:我搜索了很多,除了一个破坏WP的插件之外找不到任何东西。我使... 查看详情

WordPress 自定义帖子类型未显示在搜索结果中

】WordPress自定义帖子类型未显示在搜索结果中【英文标题】:WordPressCustomPostTypenotshowinginSearchResults【发布时间】:2016-08-1517:43:29【问题描述】:我对WordPress中的自定义帖子类型(测验)和搜索有疑问。自定义帖子类型未显示在我... 查看详情

Wordpress - 特色图像元框未显示在自定义帖子类型上

】Wordpress-特色图像元框未显示在自定义帖子类型上【英文标题】:Wordpress-FeaturedImageMetaBoxnotshowingoncustomposttype【发布时间】:2012-10-1518:58:58【问题描述】:我刚刚创建了一个自定义帖子类型,但由于某种原因,特色图片元框没有... 查看详情

Wordpress ACF 字段如何从自定义帖子类型中获取选项

】WordpressACF字段如何从自定义帖子类型中获取选项【英文标题】:WordpressACFfieldshowtoget_optionfromcustomposttypes【发布时间】:2021-07-2221:37:19【问题描述】:我使用ACF并有一个名为“关于”的页面模板,我的“关于我们”页面使用该... 查看详情

停止显示自定义帖子类型的 wordpress 搜索

】停止显示自定义帖子类型的wordpress搜索【英文标题】:stopwordpresssearchshowingacustomposttype【发布时间】:2017-02-1116:53:31【问题描述】:我有一种自定义帖子类型,可用于使用uncode主题构建的页面上的某些文本块。我需要公开这些... 查看详情

WordPress > 从自定义帖子类型获取自定义分类

】WordPress>从自定义帖子类型获取自定义分类【英文标题】:WordPress>Getcustomtaxonomyfromacustomposttype【发布时间】:2016-10-2805:24:14【问题描述】:InstalledCustomPostTypeUIwordpressplugin创建了自定义帖子类型=\'products\'使用注册了一个自... 查看详情

在单个自定义帖子类型中显示所选类别(Wordpress)

】在单个自定义帖子类型中显示所选类别(Wordpress)【英文标题】:Showingselectedcategoriesinasingleofacustomposttype(Wordpress)【发布时间】:2022-01-1508:01:23【问题描述】:我创建了一个名为members的自定义帖子类型://Customposttypesfunctionmembe... 查看详情

排序和显示自定义帖子类型 Wordpress

】排序和显示自定义帖子类型Wordpress【英文标题】:SortanddisplaycustomposttypesWordpress【发布时间】:2015-09-0823:56:30【问题描述】:所以我有一个选项页面,并创建了以下代码:add_action(\'admin_menu\',\'add_global_custom_options\');add_theme_suppor... 查看详情

在 Wordpress 中显示存档帖子

】在Wordpress中显示存档帖子【英文标题】:DisplayarchivepostsinWordpress【发布时间】:2010-06-0708:00:34【问题描述】:我希望将档案页面显示为普通的帖子页面...因此,带有二级导航的帖子页面显示:最新帖子/上个月/去年/旧在每个页... 查看详情

Wordpress - 自定义帖子类型存档页面

】Wordpress-自定义帖子类型存档页面【英文标题】:Wordpress-Customposttypearchivepage【发布时间】:2014-10-0719:13:24【问题描述】:我使用自定义帖子类型UI插件创建了一个自定义帖子类型,并使其支持存档。我有一个名为列表的CPT。我... 查看详情

如何在 wordpress 中显示自定义帖子类别名称列表

】如何在wordpress中显示自定义帖子类别名称列表【英文标题】:Howtodisplaycustompostcategorynamelistinwordpress【发布时间】:2016-08-0805:25:17【问题描述】:我的wordpress网站中有两种自定义帖子类型(图库和活动)。我想在画廊帖子类型... 查看详情