如何在循环中的wordpress循环中获取当前项目?

时间:2018-07-08 05:56:50

标签: php wordpress

我正在创建一个投资组合部分。实时站点位于http://www.nayeemriddhi.info/testproject/portfolio/。需要三个循环来显示项目。但是事实是,当我打开投资组合项目时,右侧边栏项目从一开始就显示了项目,因为我创建了循环。但我想显示右侧栏项目作为投资组合图片的当前项目。是否有任何将右侧栏项目显示为当前项目的想法。
代码在下面,

<?php

/*

Template Name: Portfolio


*/


 get_header();   ?>

    <!-- Banner -->
    <section class="page-banner" >
      <div class="container">
          <div class="row">
              <div class="col-md-12">
                  <h1 class="page-title ">Portfolios</h1>
                  <span class="page-tag-line">See our recent works</span>
                </div>
          </div>
      </div>
    </section>            



    <div class="wave-divider-pages"></div>



    <section>
        <div class="container gal-container">



                   <?php

                    $args = array(
                    'post_type' => 'custom_portfolio',
                    'posts_per_page' => '-1',
                      );
                     // the query
                     $query = new WP_Query( $args );
                      // The Loop   
                     if ( $query->have_posts() )  ?>
                    <?php while ( $query->have_posts() ) : $query->the_post() ; ?> 
                    <?php $globalID = get_the_id(); ?>
         <!-- Item-->

          <div class="col-md-4 col-sm-6 co-xs-12 gal-item">
            <div class="box">
              <a class="trigger" data-iziModal-open="#modal<?php the_ID(); ?>">
                <img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true);   ?>">
              </a>

            </div>
          </div>

          <!-- Modal-->
          <div id="modal<?php the_ID(); ?>" class="iziModal portfolio" data-izimodal-title="Portfolio Title" data-izimodal-subtitle="Web Design" style="max-width: 1200px important;">

              <div class="col_one_third p-20">


                  <?php

                    $args2 = array(
                    'post_type' => 'custom_portfolio',
                    'posts_per_page' => '6',
                      );
                     // the query
                     $query2 = new WP_Query( $args2 );
                      // The Loop   
                     if ( $query2->have_posts() )  ?>
                    <?php while ( $query2->have_posts() ) : 
                      $query2->the_post() ; ?>

                 <div class="col_half p-10">
                    <a  href="#<?php the_ID(); ?>-<?= $globalID; ?>" data-toggle="tab">
                              <img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true);   ?>" class="portfolio-thumb"/>
                    </a>       
                  </div>

         <?php endwhile; wp_reset_query();  ?>



                    <div class="col_full p-10">
                      <div class="portfolio-links">
                      <a href="#" class="btn btn-new" target="_blank">Launch Website</a>    

                       <a href="#request-quote-form" class="btn btn-danger request-quote-modal">Request a Quote</a>
                   </div>
                  </div> 

              </div>


              <div class="col_two_third col_last">
                  <div class="tab-content ">

                      <?php

                    $args3 = array(
                    'post_type' => 'custom_portfolio',
                    'posts_per_page' => '-1',
                      );
                     // the query
                     $query3 = new WP_Query( $args3 );
                      // The Loop   
                     if ( $query3->have_posts() )  ?>
                    <?php while ( $query3->have_posts() ) : 
                      $query3->the_post() ; ?>

                      <div class="tab-pane active" id="<?php the_ID(); ?>-<?= $globalID; ?>">
                          <img src="<?php echo get_post_meta($globalID, 'portfolio_image', true);   ?>" class="img-responsive"/>

                      </div>

                <?php endwhile; wp_reset_query();  ?>

                    </div>
                    </div>
                    </div>

             <!-- Item End-->

          <?php  endwhile; wp_reset_query();   ?>  

        </div>

      </section>


    <section> 




    </section> 

    <div class="wave-divider-common"></div>



    <?php get_footer();  ?>

感谢帮助...

1 个答案:

答案 0 :(得分:1)

将第一个锚标记的html修改为

<a class="trigger" data-iziModal-open="#modal<?php the_ID(); ?>" data-id="<?php the_ID(); ?>-<?= $globalID; ?>">
<img src="<?php echo get_post_meta(get_the_ID(), 'portfolio_image', true); ?>">
</a>

添加此JS

<script type="text/javascript">
$(document).ready(function(){
$('a.trigger').on('click', function (e) {
        var getDataId = $(this).data('id');
        $('.iziModal a[href="#' + getDataId + '"]').tab('show');
});
});
</script>