【按post类型查询-未显示任何内容】我正在尝试显示自定义帖子类型的帖子, 但是什么也不显示。
我已经使用CPT UI / ACF设置了所有自定义字段, 并且在显示部分之前一切似乎都很顺利。
这是我创建的blog.php模板:
<
?php
/**
* Template Name: Blog template
*
* @package Hestia
* @since Hestia 1.0
*/get_header();
?>
<
?php$args = array(
'post_type' =>
'blog', 'posts_per_page' =>
10 );
$loop = new WP_Query( $args );
?>
<
?php while ( $loop->
have_posts() ) : $loop->
the_post();
?>
<
h1>
<
?php the_field('main_title');
?>
<
h1>
<
img src="http://www.srcmini.com/<
?php the_field('header_image');
?>
" />
<
p>
<
?php the_field('paragraph_1');
?>
<
/p>
<
img src="http://www.srcmini.com/<
?php the_field('image_1');
?>
" />
<
p>
<
?php the_field('paragraph_2');
?>
<
h1>
<
img src="http://www.srcmini.com/<
?php the_field('image_2');
?>
" />
<
p>
<
?php the_field('paragraph_3');
?>
<
h1>
<
img src="http://www.srcmini.com/<
?php the_field('image_3');
?>
" />
<
?php endwhile;
?>
<
?php get_footer();
?>
function cptui_register_my_cpts_blog() {/**
* Post Type: Blog.
*/$labels = array(
"name" =>
__( "Blog", "hestia-pro" ), "singular_name" =>
__( "blog", "hestia-pro" ), "menu_name" =>
__( "Blog", "hestia-pro" ), "all_items" =>
__( "All posts", "hestia-pro" ), "add_new" =>
__( "Add new", "hestia-pro" ), "add_new_item" =>
__( "Add new post", "hestia-pro" ), );
$args = array(
"label" =>
__( "Blog", "hestia-pro" ), "labels" =>
$labels, "description" =>
"", "public" =>
true, "publicly_queryable" =>
true, "show_ui" =>
true, "show_in_rest" =>
false, "rest_base" =>
"", "has_archive" =>
false, "show_in_menu" =>
true, "exclude_from_search" =>
false, "capability_type" =>
"post", "map_meta_cap" =>
true, "hierarchical" =>
false, "rewrite" =>
array( "slug" =>
"blog", "with_front" =>
true ), "query_var" =>
true, "menu_icon" =>
"dashicons-welcome-write-blog", "supports" =>
array( "title", "editor", "thumbnail" ), );
register_post_type( "blog", $args );
}add_action( 'init', 'cptui_register_my_cpts_blog' );
‘ post_type’ 是正确的, 字段名称也是如此。它们都与自定义字段匹配, 但是由于某些原因, 什么都没有显示。
谢谢!
#1将has_archive设置为true。有同样的问题, 并解决了它。
推荐阅读
- 达到一个值并将其放在php的下一行中
- 在自定义分类模板中的WP_Query期间查询(2)ACF发布对象
- 问(如何在WordPress主题中包含js文件)
- 从TED嵌入代码中提取视频缩略图
- 将page- $ slug.php模板放在子目录中不起作用
- 以编程方式将标签添加到WordPress帖子中,而不会覆盖现有标签
- WordPress中带有wp_nav_menu()函数的移动导航菜单出现问题
- 我用Python抓取了S11全球总决赛直播评论,EDG nb
- Java入门常见错误总结