2017-03-07 24 views
0

嗨,我是WordPress開發新手。我創建了一個自定義帖子類型的「項目」,其中顯示了項目列表。我想在其單個頁面(single-project.php)中放置一個「返回項目」按鈕,該按鈕將重定向回其列表頁面。我怎樣才能做到這一點?看代碼中的最後一行。請幫忙。重定向到其單頁上的頁面

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> 

回答

0

你已經試過鏈接了嗎?

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

除非他的列表分頁,然後它會去的第一個每次。 如果它被分頁,他可以將頁碼保存在一個會話中,並從中創建一個變量,所以像這樣:href =「index.php/projects/<?php echo $ pageNumber?>」(取決於鏈接結構) – Stender

0

試試這個,它應該工作

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