Php 从单个页面重定向回列表页面

Php 从单个页面重定向回列表页面,php,wordpress,Php,Wordpress,嗨,我是WordPress开发的新手。我已经创建了一个自定义的“项目”帖子类型,其中显示了项目列表。我想在它的单个页面(single project.php)中放置一个按钮“Back to Projects”,它将重定向回它的列表页面。我该怎么做?请看代码中的最后一行。请帮忙 if ($query->have_posts() ): while ($query->have_posts() ): $query->the_post();

嗨,我是WordPress开发的新手。我已经创建了一个自定义的“项目”帖子类型,其中显示了项目列表。我想在它的单个页面(single project.php)中放置一个按钮“Back to Projects”,它将重定向回它的列表页面。我该怎么做?请看代码中的最后一行。请帮忙

 if ($query->have_posts() ):
        while ($query->have_posts() ):
            $query->the_post();
                                    ?>

                                    <div class="related-project-single">
                                        <?php the_post_thumbnail('image_size_720_680'); ?>
                                        <div class="wrapper-button">
                                            <a class="bp-button bp-button-plain button-yellow btn-slider" href="<?php the_permalink(); ?>"><?php echo esc_html__('view project','inspiry') ?> <i class="fa fa-chevron-right"></i></a>
                                        </div>
                                        <div class="wrapper-location">
                                            <h3><?php the_title(); ?></h3>
                                            <?php
                                            $feature_location_related = get_post_meta(get_the_ID(),'bp-location',true);
                                            if(!empty($feature_location_related)){
                                                ?>
                                                <p class="featured-location"><?php echo esc_html($feature_location_related);?></p>
                                                <?php
                                            }
                                            ?>
                                        </div>
                                    </div>
                                    <?php
                                endwhile;endif;?>
                            <a href="">Back to projects</a>
if($query->have_posts()):
而($query->have_posts()):
$query->the_post();
?>


您尝试了链接此链接的方法

<a href="index.php?post_type=projects">Back to projects</a>

试试这个,它应该可以工作

  <a href="<?php echo get_post_type_archive_link('projects'); ?>">Back to projects</a>

除非他的列表被分页,否则每次都会转到第一个列表。如果它被分页,他可以在会话中保存页码,并从中创建一个变量,例如href=“index.php/projects/”(取决于链接结构)