JavaScript 不会在内容区域 wordpress 之外工作
JavaScript wont work outside of content area wordpress
基本上我正在使用wordpress,我希望我的分享链接随着用户向下滚动而跟随帖子。我可以让它完全按照我想要的方式工作,除了我已将 JavaScript 直接附加到内容中.php这意味着当页面显示多个帖子时,JavaScript 会在页面上多次加载。这导致粘性功能仅适用于前几个帖子。我尝试将我的javascript移动到标题,但没有运气。请有人帮帮我!!以下是我的内容.php文件,仅适用于前几篇文章。
<script src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.js"></script><script src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.stickem.js"></script>
<script>
$(document).ready(function() {
$('.container').stickem();
});
</script><div class="title-wrapper"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><a href="<?php the_permalink(); ?>#comments" title="<?php comments_number( 'No Comments', '1 Comment', '% Comments' ); ?>"><div class="commentnumber"><?php comments_number( '0', '1', '%' ); ?></div></a></div><div class="container"><div class="stickem-container"><div class="thelinks stickem"><div class="sharelinks"><div class="sharepinterest"><?php echo get_simple_local_avatar( $id_or_email, $size, $default, $alt ); ?></div><a href="http://www.facebook.com/sharer/sharer.php?s=100&p[url]=<?php the_permalink(); ?>&p[images][0]=http://www.otlcampaign.org/sites/default/files/journey-for-justice-mlk-memorial.jpg&p[title]=<?php the_title(); ?>&p[summary]=Click+to+enlarge"><div class="sharefacebook"></div></a><a href="http://twitter.com/home?status=<?php the_title(); ?>+<?php the_permalink(); ?>"><div class="sharetwitter"></div></a><div class="sharegoogle"></div></div></div>
<div class="post-wrapper"><div class="entry-content"> <a href="<?php the_permalink(); ?>"><?php the_content(); ?></a>
</div></div></div>
</div><a>
尝试将其粘贴在页脚中。
如果这不起作用,请在控制台中查找容器,您可以从
$(document).ready
自
$(".container").change
// or whatever the css selector for the container is
这样,stickem() 将在容器更改的那一刻触发,也就是加载新帖子。
您需要
将代码移动到页脚.php文件中,并进行以下更改:
<script src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.stickem.js"></script>
jQuery(document).ready(function($) {
$('.container').stickem();
});
默认情况下,WordPress启用了jQuery无冲突,因此您必须使用jQuery
而不是使用$
。这也意味着您不需要包含:
<script src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.js"></script>
相关文章:
- 如何使MailHandler.php在Wordpress中工作
- .load ajax无法正常工作whitin wordpress主题
- 更新Wordpress和我的平滑滚动停止工作
- JS错误导致WordPress插件无法工作
- Wordpress WooCommerce添加到购物车,无法在移动网站上工作
- 谷歌地图API停止在Wordpress模板中工作
- 正在尝试获取此代码'在wordpress页面中工作的功能
- onmouseover无法在wordpress中工作
- wordpress 4.1 javascript停止工作
- 让Ajax为Wordpress上的所有用户工作
- j查询同位素错误.停止在 Wordpress 中工作
- WordPress jQuery灯箱突然不工作
- 无法让我的下拉菜单在基于引导的 Wordpress 主题中工作
- 我的Wordpress网站上的所有jQuery脚本都无法正常工作
- 导致WordPress管理部分无法工作的滚动代码
- 让jQuery在Wordpress中工作时遇到麻烦
- 为什么AJAX $.post不能在wordpress中工作
- JavaScript在纯HTML上工作,但不在Wordpress网站上工作
- JavaScript 不会在内容区域 wordpress 之外工作
- 如何让我的脚本在wordpress中工作