Flexslider的深层链接问题

时间:2019-06-13 10:24:08

标签: javascript php wordpress flexslider

我正在使用flexslider显示自定义帖子类型的帖子。通过将帖子ID添加到每个li元素,并在单击上一个/下一个时使用该ID更新该URL,我已经设法获得了深层链接。

但是,当它在浏览器中被拉出时,我无法使这个新链接正常工作。例如,目标是使用此URL在Facebook上共享。当有人单击该网址时,应转到该特定的幻灯片。

$(document).ready(function(){
    var $flexslider = $('.flexslider');     
                $flexslider.flexslider({
before:function (slider) {
          // get the ID of the slide we are animating to
          id = slider.slides[slider.animatingTo].id 
          // set the URL path to #slideID     
          history.pushState(null, null, "#" + id);
          },
                animation: "fade",
                                touch: false,
                                slideshow: false,
                manualControls: ".flex-control-nav li",
                useCSS: false /* Chrome fix*/               
});
});

<section id="slider">
      <div class="flexslider">
        <ul class="slides">
        <?php query_posts(array('post_type' => 'juweel','orderby' => 'rand')); if(have_posts()) : while(have_posts()) : the_post();?>
            <li data-thumb="<?php the_post_thumbnail_url(); ?>" class="slide" id="<?php the_ID(); ?>">
            <?php the_title(); ?>
            <?php the_post_thumbnail(); ?>
          </li>
        <?php endwhile; endif; wp_reset_query(); ?>
        </ul>
    </div>
</section>

我知道我可以使用来获取当前位置的哈希值

var hash = window.location.hash;

但是我不知道如何检查该值是否与我的一张幻灯片的ID相匹配并将其放到那里

0 个答案:

没有答案
相关问题