在自定义帖子类型滑块上添加导航链接

时间:2016-01-18 17:05:35

标签: javascript jquery wordpress custom-post-type testimonials

我正在从头开始研究Wordpress主题。我有几个部分,其中一部分显示视频和一些推荐。我已经设法构建(像这样:http://www.wpbeginner.com/wp-tutorials/how-to-add-rotating-testimonials-in-wordpress/)一个漂亮的动态推荐滑块,使用自定义帖子类型(每个推荐都是一个帖子)和一个隐藏和显示每个帖子的脚本,进行简单但有趣的过渡。

现在我需要在滑块下添加一个类似Carousel的导航(带有那些漂亮的小点)。问题是:我尝试了很多解决方案,但没有一个能够解决问题。有人可以为我照亮吗?

以下是我用来显示自定义帖子循环的代码:

<div class="depo-wrap">
   <div class="depoimentos">
   <?php
      $args = array( 'post_type' => 'testimonial', 'posts_per_page' => 10 );
      $loop = new WP_Query( $args );
      if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
      $data = get_post_meta( $loop->post->ID, 'testimonial', true );
      static $count = 0;

      if ($count == "1") { ?>
         <div class="slide" style="display: none;">
            <div class="citacao"><?php the_content(); ?></div>
            <div class="info-pessoal"><?php echo $data[ 'nome-pessoa' ]; ?><span> | </span><?php echo $data[ 'local-origem' ]; ?></div>
            <div class="cargo"><?php echo $data[ 'cargo' ]; ?></div>
         </div>
      <?php } else { ?>
         <div class="slide">
            <div class="citacao"><?php the_content(); ?></div>
            <div class="info-pessoal"><?php echo $data[ 'nome-pessoa' ]; ?><span> | </span><?php echo $data[ 'local-origem' ]; ?></div>
            <div class="cargo"><?php echo $data[ 'cargo' ]; ?></div>
         </div>

    <?php 
       $count++; } 
       endwhile; 
       endif; ?>
    </div>
</div>

以下是使一切正常的脚本:

$(document).ready(function(){
  $('.depoimentos .slide');
  setInterval(function(){
    $('.depoimentos .slide').filter(':visible').fadeOut(1000,function(){
      if($(this).next('.slide').size()){
        $(this).next().fadeIn(1000);
      } else {
        $('.depoimentos .slide').eq(0).fadeIn(1000);
      }
    });
  }, 15000); 
});

TL; DR:我在这里有这个代码,我正在尝试添加一些类似Carousel的子弹,甚至是一些next / prev按钮。我只想添加一个导航到我在Wordpress中使用自定义帖子类型创建的推荐幻灯片。

1 个答案:

答案 0 :(得分:0)

添加Bootstrap Carousel有效(感谢@Enrico)!这里的代码有一些修改:

<div id="carousel-depoimentos" class="carousel slide carousel-fade" data-ride="carousel" data-interval="1000">
   <div class="carousel-inner depoimentos">
      <?php
         $args = array( 'post_type' => 'testimonial', 'posts_per_page' => 1 );
         $loop = new WP_Query( $args );
         if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
         $data = get_post_meta( $loop->post->ID, 'testimonial', true );
      { ?>

   <div class="item active">
      <div class="citacao"><?php the_content(); ?></div>
      <div class="info-pessoal"><?php echo $data[ 'nome-pessoa' ]; ?><span> | </span><?php echo $data[ 'local-origem' ]; ?></div>
      <div class="cargo"><?php echo $data[ 'cargo' ]; ?></div>
   </div>

   <?php 
      }
      endwhile; 
      endif; 
      wp_reset_postdata();
   ?> 

   <?php
      $args = array( 'post_type' => 'testimonial', 'posts_per_page' => 10, 'offset' => 1 );
      $loop = new WP_Query( $args );
      if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
      $data = get_post_meta( $loop->post->ID, 'testimonial', true );
   { ?>

   <div class="item">
      <div class="citacao"><?php the_content(); ?></div>
      <div class="info-pessoal"><?php echo $data[ 'nome-pessoa' ]; ?><span> | </span><?php echo $data[ 'local-origem' ]; ?></div>
      <div class="cargo"><?php echo $data[ 'cargo' ]; ?></div>
   </div>

   <?php 
      }
      endwhile; 
      endif; 
      wp_reset_postdata();
   ?>
   </div>                       
</div>