【发布时间】:2023-03-30 10:50:01
【问题描述】:
我创建了一个自定义帖子类型,然后显示自定义帖子数据,但是当我点击该自定义帖子的阅读更多按钮时,它给了我一个错误page not found当我点击阅读更多按钮时,它指向像这样的网址@987654322 @ 这里 abc 是自定义的帖子。我正在与您分享我到目前为止所做的事情。
自定义帖子类型
<?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