简体   繁体   English

带有帖子页面 WordPress 的自定义帖子类型链接

[英]Custom Post Type link with post page WordPress

I have create a custom post type and then displaying custom post data but when I click on read more button of that custom post it's giving me an error page not found when I click on read more button it's pointing url like this domain.com/abc/my-custom-post here abc is custom post slug.我创建了一个自定义帖子类型,然后显示自定义帖子数据,但是当我单击该自定义帖子的“阅读更多”按钮时,当我单击“阅读更多”按钮时,它给了我一个page not found的错误page not found它指向的 url 是这样的domain.com/abc/my-custom-post这里的abc是自定义的 post slug。 I am sharing you what I did till now.我正在与您分享我到目前为止所做的事情。

Custom Post Type自定义帖子类型

<?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' );
?>

Displaying custom post code显示自定义邮政编码

<?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();

?>

Let me know how to connect with post page when clicking read more button.单击“阅读更多”按钮时,让我知道如何连接帖子页面。

我已经检查了你的代码,它是完美的,但你可以按照给定的屏幕截图按照说明来解决你的问题http://prntscr.com/mozub7 ,这是参考链接希望你的问题得到解决。

do you save permalink?你保存永久链接吗? in wp dash go >> settings>permalinks and save changes one time在 wp dash go >> settings>permalinks 并保存一次更改

Your code is working correctly.您的代码工作正常。 Try again to save the permalinks settings再次尝试保存永久链接设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM