Twitter Bootstrap popovers无法在Wordpress循环中运行

时间:2013-01-04 05:54:24

标签: php html wordpress twitter-bootstrap

我一直试图让自举弹出窗口在Wordpress循环中工作但没有成功,这是我到目前为止所做的:

<?php while($have_posts()): $the_post();
  $excerpt = strip_tags(get_the_excerpt());?>

  <a class="<?php echo the_ID()?>" href="<?php echo the_permalink();?>"><?php echo the_title();?></a>

  <script>
  jQuery('.<?php echo the_ID()?>').mouseenter(function(){
    jQuery(this).popover({
      html: true,
      title: '<?php echo the_title();?>',
      trigger: 'manual',
      placement:'top',
      content:'<?php echo $excerpt;?>'
    }).popover('show');
  });
  </script>
<?php endwhile;?>

打印出我期望的内容

<a class="5598" href="http://mysite.oom/post/">Post Title</a>

<script>
jQuery('.5598').mouseenter(function(){
  jQuery('.5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

etc...

然而,弹出窗口没有显示悬停,我没有得到任何脚本错误,所以我不知道为什么弹出窗口不起作用,我有jQuery,bootstrap.js和bootstrap。 css包含在页面加载中。任何帮助将不胜感激!

由于

1 个答案:

答案 0 :(得分:2)

从数字开始时,类和ID不起作用!

众所周知,当你把班级作为一个数字时:

<div class="1234">...</div>

它不起作用。在你的情况下,它是这样的:

<script>
jQuery('.5598').mouseenter(function(){
  jQuery('.5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

班级是纯数字。 5598。不行。所以尝试用以下内容替换它:

<a class="p5598" href="http://mysite.oom/post/">Post Title</a>

<script>
jQuery('.p5598').mouseenter(function(){
  jQuery('.p5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

还有一件事我怀疑,.popover()是一个函数,就像实例化一样。所以,不要在.mouseenter()下给它。以这种方式替换整个脚本:

<script>
jQuery(document).ready(function(){
  jQuery('.p5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  })
  jQuery('.p5598').hover(function() {
    jQuery('.p5598').popover('show');
  }, function(){
    jQuery('.p5598').popover('hide');
  });
});
</script>