自定义帖子类型链接与帖子页面WordPress

问题描述 投票:1回答:3

我已经创建了一个自定义的帖子类型,然后显示自定义的帖子数据但是当我点击阅读更多按钮的那个自定义帖子它给我一个错误page not found当我点击阅读更多按钮它指向网址像这样domain.com/abc/my-custom-post这里abc是自定义帖子slug。我和你分享我迄今所做的一切。

自定义帖子类型

<?php
    function create_posttype() {

    register_post_type( 'abc',
    array(
    'labels' => array(
    'name' => __( 'ABC' ),
    'singular_name' => __( 'ABC' ),
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', )
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'abc'),
    )
    );
    }
    add_action( 'init', 'create_posttype' );
?>

显示自定义邮政编码

<?php
    $args = array(
    'post_type' => 'abc',
    'posts_per_page' => -1
    );
    $wp_query = new WP_Query($args);
    while($wp_query->have_posts()) : $wp_query->the_post();
    echo get_field('featured_image');
    the_title();
    echo get_the_excerpt();
    endwhile;
    wp_reset_query();

?>

点击“阅读更多”按钮,让我知道如何连接帖子页面。

php wordpress custom-post-type
3个回答
1
投票

我检查了你的代码,它是完美的但在这里你可以按照给定的截图按照说明来解决你的问题http://prntscr.com/mozub7这是reference link希望你的问题得到解决。


0
投票

你保存永久链接?在wp dash中>>设置>永久链接并保存更改一次


0
投票

您的代码工作正常。再次尝试保存永久链接设置

© www.soinside.com 2019 - 2024. All rights reserved.