如何在wordpress博客的单个页面中显示所有帖子的特色图片

如何在wordpress博客的单个页面中显示所有帖子的特色图片,wordpress,custom-wordpress-pages,Wordpress,Custom Wordpress Pages,我正在制作一个WordPress主题,现在我想在一个名为gallery的页面中显示每个帖子的特色图片,并应根据帖子的类别进行排序。将以下代码添加到模板文件中,并根据需要进行更改 <?php //loop through category $cat_args=array( 'orderby' => 'name', 'order' => 'ASC' ); $categories=get_categories($cat_args); foreach($categori

我正在制作一个WordPress主题,现在我想在一个名为gallery的页面中显示每个帖子的特色图片,并应根据帖子的类别进行排序。

将以下代码添加到模板文件中,并根据需要进行更改

<?php
//loop through category
$cat_args=array(
    'orderby' => 'name',
    'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) { 
    //loop through posts of category
    $args=array(
        'post_type' => 'post',
        'posts_per_page' => -1,
        'category__in' => array($category->term_id)
    );
    $posts=get_posts($args);
    if ($posts) {
        echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '">' . $category->name.'</a> </p> ';
        foreach($posts as $post) {
            setup_postdata($post);
            // if only featured image set
            if ( has_post_thumbnail() ) {
            ?>
            <a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('full'); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" /><br /><?php the_title(); ?></p>
            <?php
            }
        }
    }
}
?>


以下代码将仅显示特色图像(称为“\u post\u缩略图()”):



您是否已经有图库页面或需要创建图库页面?您可以使用
get_posts
the_post\u缩略图
来执行帖子循环。已经有很多文章了。请展示您到目前为止所做的工作以及失败的地方。此外,您可能需要阅读和阅读。请注意,这不是一个免费的代码编写服务。。。
    <?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        the_post_thumbnail();
    }  //end while
} //end if
?>