【问题标题】:How to call wordpress custom post type page如何调用wordpress自定义帖子类型页面
【发布时间】:2015-12-15 23:15:50
【问题描述】:

我在 WordPress 中创建了一个自定义帖子类型,并且我还将其单独的两个页面设置为 single-acme_product.php、archive-acme_product.php 但问题是当我从自定义帖子类型上传帖子时,它的显示 index.php

这是我的函数代码

function new_post_type_wp(){

    register_post_type('acme_product',
            array(
                'labels' => array(
                    'name' => __('Products'),
                    'singular_name' => __('Product')
                ),
                'public' => true,
                'has_archive' => true,
            )
        );
}
add_action('init','new_post_type_wp');

请告诉我如何将我的自定义帖子导航到特定的自定义页面

参考链接https://codex.wordpress.org/Post_Types

【问题讨论】:

  • Usman 不清楚您面临什么问题。能否请您添加更多信息。
  • 亲爱的,我创建了一个自定义帖子类型,我只想在 single-acme_product.php 上显示我的自定义帖子,这个问题我为自定义帖子参考链接 @987654322 创建了一个单独的页面 single-acme_product.php @ 但是帖子显示在 single-acme_product.php 他们显示在 index.php 我只想在我的 single-acme_product.php 上显示这些帖子你明白了吗??
  • 是的,我收到了,感谢您提供更多信息。您的自定义帖子类型不应出现在 index.php 上。请使用此链接生成 cpt 代码 themergency.com/generators/wordpress-custom-post-types 并确保您设置了重写选项,以便您的自定义帖子类型可在 /cpt/single-item-name
  • 亲爱的我的cpt代码是完美的,但是cpt的帖子不能导航single-spt.php并且您发送它的链接也会生成cpt,我只需要cpt帖子导航到single-cpt。 php
  • 转到wordpress仪表板,设置->永久链接然后保存(无需更改选项)。然后尝试,如果不让我知道还有另一件事要尝试

标签: wordpress wordpress-theming custom-post-type


【解决方案1】:

您是否在特定页面中尝试过这种自定义帖子类型?

$args = array( 'post_type' => 'acme_product', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;

【讨论】:

  • 实际您的代码是完美的,问题出在我的主题中,我复制粘贴默认主题文件,它们运行良好,之后我知道问题出在哪里,谢谢亲爱的你给我很好的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
  • 2014-05-20
  • 2016-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多