WordPress自定义帖子类型在现有页面上显示自定义帖子类型的列表 [英] Wordpress Custom Post type displaying list of custom post type on existing page

查看:123
本文介绍了WordPress自定义帖子类型在现有页面上显示自定义帖子类型的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义帖子类型来记录数据,该数据将在现有页面上显示为列表/表。

I've create a custom post type to record data which will be displayed as a list/table on an existing page.

数据不需要具有它是自己的页面。数据将显示在表格的现有页面上。

The data does not need to have it's own page. The data will be displayed on an existing page in a table.

我正在使用高级自定义字段:中继器,但由于数据集较大,该页面花费了很长时间来处理管理部分中的数据。

I was using Advanced Custom Fields: Repeater but because of the large data set the page was taking a long time to process the data in the admin section.

我创建了自定义帖子,这里没有问题。

I've created the custom post, no issues here.

我只是不知道如何在现有模板中显示自定义帖子数据。

I just don't know how to display the custom post data in an existing template.

 <?php query_posts( array('post_type'=>array('page','Custom_Post_Type'))); ?> 

当我在循环之前添加此代码时,它将显示所有页面和所有自定义帖子类型。我只希望它显示单个页面+所有自定义帖子类型

When I add this code before the loop it display all pages and all custom post types. I just want it to display the individual page + All Custom Post Types

推荐答案

尝试此代码,将其粘贴到表的任何位置成为。您可以访问循环中所有帖子的信息,而不仅仅是标题。

Try this code, paste it wherever you want the table to be. You have access to all of the post's info inside the loop, not just the title.

$the_query = new WP_Query( array( 'post_type' => 'Custom_Post_Type' ) );

while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<tr><td>';
    the_title();
    echo '</td></tr>';
endwhile;

wp_reset_postdata();

这篇关于WordPress自定义帖子类型在现有页面上显示自定义帖子类型的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆