jQuery Cycle pagerAnchorBuilder Wordpress 模块化主题
Modularity Wordpress 主题包括一个围绕 jQuery Cycle 构建的“帖子滑块”。它使用寻呼机在滑块上方显示一个小数字。我希望能够将该数字更改为帖子标题。
主题中的代码如下:
$doc_ready_script .= '
jQuery(function() {
jQuery("#slider-posts").cycle({
fx: "scrollHorz",
timeout: 0,
prev: "#prev",
next: "#next",
pager: "#slider-nav",
containerResize: 0
});
});';
我不是 jQuery 编码员(正如您可能知道的那样!),我认为对代码进行简单调整即可达到目的:
$doc_ready_script .= ' jQuery(function() {
jQuery("#slider-posts").cycle({
fx: "scrollHorz",
timeout: 0,
prev: "#prev",
next: "#next",
pager: "#slider-nav",
containerResize: 0,
pagerAnchorBuilder: function(idx, slide) {
return '<li><a href="#">' + jQuery(slide).children("h2").eq(0).text() + '</a></li>';
}
});
});';
但是,我现在收到一条错误消息“解析错误:语法错误,意外的 '>'”。
所以,我意识到我做了一件非常愚蠢的事情!
有哪位 jQuery 大师可以给我指出正确的方向吗?
非常感谢期待!
The Modularity Wordpress theme includes a "post slider" built around jQuery Cycle. It uses pager to display a small number above the sliders. I would love to be able to change that number into the post title.
The code in the theme is as follows:
$doc_ready_script .= '
jQuery(function() {
jQuery("#slider-posts").cycle({
fx: "scrollHorz",
timeout: 0,
prev: "#prev",
next: "#next",
pager: "#slider-nav",
containerResize: 0
});
});';
I am NOT a jQuery coder (as you might be able to tell!) and I thought a simple adjustment to the code as follows would do the trick:
$doc_ready_script .= '
jQuery(function() {
jQuery("#slider-posts").cycle({
fx: "scrollHorz",
timeout: 0,
prev: "#prev",
next: "#next",
pager: "#slider-nav",
containerResize: 0,
pagerAnchorBuilder: function(idx, slide) {
return '<li><a href="#">' + jQuery(slide).children("h2").eq(0).text() + '</a></li>';
}
});
});';
However, I now get an error saying "Parse error: syntax error, unexpected '>'".
So, I realise that I have done something really daft!
Can some kind jQuery guru point me in the right direction please?
Many thanks in anticipation!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的网站需要完全相同的功能。您需要首先使用 .map() 函数构建数组。然后,您可以在 pagerAnchorBuilder 函数中循环访问该数组。
查看教程我已经写了。它将准确地向您展示如何让它发挥作用!
I needed the exact same functionality on my website. You need to build the array first using the .map() function. You can then loop through this array in the pagerAnchorBuilder function.
Check out the tutorial I've written. It'll show you exactly how to get this working!