在Wordpress中显示“帖子类型”列表的文件是什么


What is the file to display a list of "post type" in Wordpress?

我正在寻找可以显示我的列表帖子类型的文件。我试图在archive-posttype.php展示,但我没有成功。

<?php 
$newsArgs = array( 'post_type' => 'agenda', 'posts_per_page' => 4);                                    
$newsLoop = new WP_Query( $newsArgs );                                        
while ( $newsLoop->have_posts() ) : $newsLoop->the_post();
?>
<?php the_post_thumbnail(); ?>
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<p><strong><?php the_time('d.m.Y') ?></strong></p>
<p><?php the_content(); ?></p>
<p><?php //echo get_the_term_list( $post->ID, 'categorias', 'Categorias: ', ' '); ?></p>
<p>Local: <?php echo get_post_meta($post->ID, 'valor_meta', true); ?></p>       
<?php endwhile; ?>

代替$posttype,您必须放置实际的帖子类型名称,因此,如果您注册了 CPT 名称agenda可以显示的文件是 archive-agenda.php .您可以在此处和此处找到更多信息。

顺便说一句,如果您在 ( archive-agenda.php ( 中显示您的 CPT(例如agenda(并使用"漂亮的永久链接" - 您用于显示议程的 url 是 your-site-name.com/agenda/ ,那么无需使用自定义查询来显示它们,您可以使用默认循环,即在文件archive-agenda.php中您可以像往常一样显示您的自定义帖子:

if ( have_posts() ) {
   while( have_posts() ) : the_post();
      the_title();
   endwhile;
endif;