如何在网站上显示CPT UI插件的数据?

问题描述:

我已经使用CPT UI来添加一些分类标题。我已经在CPT UI中填写了两篇文章数据以供练习。现在我想在页面上显示这些帖子。我必须写的所有代码。如何在网站上显示CPT UI插件的数据?

为了拉入自定义字段/后期元,您需要在模板文件的WordPress循环中编写一些代码(https://codex.wordpress.org/The_Loop)。

The Loop是WordPress用来显示帖子的PHP代码。使用The Loop,WordPress会处理每个帖子以显示在当前页面上,并根据它与The Loop标签中指定条件的匹配格式。循环中的任何HTML或PHP代码将在每篇文章中处理。

例如,

if (have_posts()) { 
    while (have_posts()) { 
     the_post(); 
     // 
     // Post Content here 
     // 
    } // end while 
} // end if 

对于所有的后元:

$meta = get_post_meta(get_the_ID()); echo '<pre>'; print_r($meta); echo '</pre>';

或单个值:

$custom_field_value = get_post_meta(get_the_ID(), 'custom_field_key_name', true);

请阅读下面的WordPress的法典的更多信息:

https://codex.wordpress.org/Custom_Fields

https://developer.wordpress.org/reference/functions/get_post_meta/

+0

你是什么意思“的WP环路内您的模板文件:“ –

+0

答案已更新,更多信息 – Matthew

您可以使用Wp_Query与您使用CPT UI插件来显示这些职位创造的职位名称一起。像例如我已经创建了一个名为学校,然后代码,以显示学校类型的所有帖子员额如下:

$query = new WP_Query(array('post_type' => 'school')); 
while($query->have_posts()): 
    $query->the_post(); 
    echo $query->ID; // it will print the ID of post 
endwhile; 

希望这将清除的东西..

+0

如果有任何答案帮助,请不要忘记进行投票;-) – Matthew