#028 – 事件、管理和 UI

在最后一个视频中,我们学习了如何执行自定义循环并从我们的自定义帖子类型和自定义字段中输出自定义数据。这一次,我们需要再次执行此操作,只是针对稍微更复杂的事件部分。我们需要一个专门用于事件区域的自定义页面模板,以便我们有一个可以编写所有这些自定义代码的地方。

查询

$the_query = new WP_Query(array(
  'post_type' => 'events',  // This is the name of our custom post type
  'posts_per_page' => -1    // -1 means "all of them"
));

循环

while ($the_query->have_posts()) : $the_query->the_post(); ?>

  // we're in the loop!

endwhile;

在循环内部,我们可以使用 ACP API 输出自定义字段

the_field("date_start");

现在只剩下将它正确地进行样式设置,并确保我们正在输出要显示的每一个数据。