WordPress缩略图网格展开预览
Wordpress thumbnail grid expanding preview
我在这里找到了这个很棒的教程:codrops
演示
但是我不知道如何让它在 Wordpress 中工作!我是Javascript的初学者/中级,但我真的不确定如何将其插入Wordpress。Wordpress Codex提到将脚本直接放入帖子中,因为它不会在整个站点范围内使用。有没有人成功地让这个工作?你能给我说明怎么做吗?
这是您可以做到的一种方法。通过在函数.php文件中创建一个短代码,您可以包含所需的 js 资源。请注意,对于此实现,您必须包含以下行中定义的本地资源:element.src = '/wp-content/themes/custom_name_space/js/$src';
或者您可以使用某种插件,让您在帖子中添加自定义 js。
/** you will need to include this invocation in the source file. */
$(function() {
Grid.init();
});
<?php add_shortcode( 'custom_name_space_addJs', function ( $atts ) {
/**
* create a javascript shortcode
* shortcode takes an id attribute and src attribute
* leaving src attribute blank will generate a 404 Error Code
*/
extract( shortcode_atts( array(
'id'=>'js-custom_name_space-script', 'src' => 'no-script.js', ), $atts ) ); return "
<script id='js-add-script-element'>
(function(w, doc) {
'use strict';
function downloadJSAtOnload() {
var element = doc.createElement('script');
element.id = '$id';
element.src = '/wp-content/themes/custom_name_space/js/$src';
doc.body.appendChild(element);
}
/* Check for browser support of event handling capability */
if (w.addEventListener) {
w.addEventListener('load', downloadJSAtOnload, false);
} else if (w.attachEvent) {
w.attachEvent('onload', downloadJSAtOnload);
} else {
w.onload = downloadJSAtOnload;
}
}(window, document));
</script>"; }); ?>
<!-- Then inside a wordpress post, write the needed HTML from the tutorial and use the short code -->
[custom_name_space_addJs id="thumb-grid" src="grid.js"]
相关文章:
- 剑道网格jQuery动画()问题
- 使用Dnamics CRM 2011中的JavaScript读取子网格的所有记录,而不考虑活动页面
- 我可以更改剑道UI网格吗's的外键值
- jqGrid树网格问题
- 通过点击按钮翻转缩略图
- 在Three.js中导出网格会提高性能吗
- 如何在剑道网格初始化后设置pageSizes
- 在threejs中使用纹理网格和线框网格
- 如何在可分组的剑道网格中设置空数据文本
- 如何在Angular UI网格中选择下一行
- 在Codrops的内容中添加数组元素展开缩略图网格预览
- IE 9在展开缩略图网格版本中单击失败
- Zurb Foundation 4清除块网格中的Lightbox缩略图
- 需要创建动态缩略图网格
- 在网格中显示缩略图图像,并扩展预览
- 缩略图网格问题
- 引导网格缩略图与扩展预览点击
- 使用Picnicss在Ember中创建缩略图网格
- WordPress用缩略图扩展网格
- WordPress缩略图网格展开预览