使用自定义帖子在WordPress主题中创建幻灯片

时间:2016-08-22 作者:V.R

我正在尝试集成一个html模板。它有一个滑块。每张幻灯片包含6幅图像。单击图像会打开一个模式,其中包含图像的详细信息。目前,我用一页自定义帖子来实现这一点,其中包含6个用于上传图像的元盒。说到模态,我就卡住了。有没有更好的方法

 <section id="products" >
    <div class="container">
      <div class="section-title">
        <div class="sticker">
          <div class="icon">
            <i class="fa fa-archive"></i>
          </div>
          <h1>products</h1>
        </div>
        <div class="excerpt">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eleifend odio nunc, ac commodo augue sollicitudin vitae. Donec quam risus, fermentum in luctus at, sodales eget mauris.
        </div>
      </div>
    </div>

    <div id="products-grid" class="row">
      <div class="container products-holder">
        <div class="row products-holder-item">
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
        </div>
        <div class="row products-holder-item">
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
        </div>
        <div class="row products-holder-item">
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

              </div> 
              </a> 
            </div>
          </div>
          <div class="col-md-4">
            <div class="product-item">
            <a  href="#myModal" id="openBtn" data-toggle="modal" >
              <div class="product-image">
                <img src="images/news-img.jpg" alt="">
              </div>
              <div class="product-desc">
                <div class="product-title">
                  <h4>Lorem Ipsum</h4>
                </div>

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



        </div>

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

1 个回复
最合适的回答,由SO网友:shema 整理而成

也许在post循环中,您需要使用get\\u post\\u type()函数添加一个检查post类型的条件。

这样的话:

<?php if(have_posts()) : ?>
     <?php while(have_posts()) : the_post(); ?> 
           <?php if(get_post_type(get_the_ID()) === \'your custom post type\') : ?>

                    //Your slider code with current post data


           <?php endif; ?>
      <?php endwhile; ?>
 <?php endif; ?>
很明显,如果找不到帖子类型或i have\\u帖子没有返回任何内容,您可以添加额外的条件。

相关推荐

如何在WooCommerce总价金额->ProductPages下增加保证金

我对ProductPage上的woocommerce价格金额有两个问题。第一个问题:我想在总价格金额下增加更多保证金,并按下“添加到卡”按钮我怎样才能做到这一点?(示例见下图)第二我只想显示总价。现在我得到了可变产品的最低价格,显示在产品标题下面,以及总价格金额。我只想显示总价。已经谢谢你了!