如何将jCarousel与PHP函数一起使用?
我仍在学习PHP和jQuery,在我看来这是一件相当复杂的事情 我希望能够使用jCarousel的textscroller功能来显示由PHP函数生成的URL列表,而不是jCarousel编写的XML提要和URL。演示: 我想使用的WordPress PHP函数为WordPress类别中的一些或所有帖子生成一个带有html标记的URL列表 因此,我认为我不需要jCarousel的XML函数或html创建者函数,也不需要截断字符串 那么,是否可以在jQuery函数中包含PHP函数,或者让jQuery函数从PHP函数中检索URL列表,类似于向jCarousel提供XML提要?我需要使用jQuery PHP库吗 任何答案都将不胜感激标记 这是使用XML提要的jCarousel函数:我省略了documentready函数如何将jCarousel与PHP函数一起使用?,php,jquery,jcarousel,Php,Jquery,Jcarousel,我仍在学习PHP和jQuery,在我看来这是一件相当复杂的事情 我希望能够使用jCarousel的textscroller功能来显示由PHP函数生成的URL列表,而不是jCarousel编写的XML提要和URL。演示: 我想使用的WordPress PHP函数为WordPress类别中的一些或所有帖子生成一个带有html标记的URL列表 因此,我认为我不需要jCarousel的XML函数或html创建者函数,也不需要截断字符串 那么,是否可以在jQuery函数中包含PHP函数,或者让jQuery
function mycarousel_initCallback(carousel, state)
{
carousel.lock();
jQuery.get(
'special_textscroller.php',
{
'feed': 'http://jquery.com/blog/feed/atom/'
},
function(xml) {
mycarousel_itemAddCallback(carousel, xml);
},
'xml'
);
};
function mycarousel_itemAddCallback(carousel, xml)
{
var $items = jQuery('item', xml);
$items.each(function(i) {
carousel.add(i + 1, mycarousel_getItemHTML(this));
});
carousel.size($items.size());
// Unlock and setup.
carousel.unlock();
carousel.setup();
};
/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item)
{
return '<h3><a href="'+$('link', item).text()+'">'+$('title', item).text()+'</a></h3><p>'+mycarousel_truncate($('description', item).text(), 90)+'</p>';
};
/**
* Utility function for truncating a string without breaking words.
*/
function mycarousel_truncate(str, length, suffix) {
if (str.length <= length) {
return str;
}
if (suffix == undefined) {
suffix = '...';
}
return str.substr(0, length).replace(/\s+?(\S+)?$/g, '') + suffix;
};
这个WordPress PHP函数:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=10'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><br /><br /><?php endwhile; ?>
生成如下所示的html:
<a href="URL" rel="bookmark">link title</a><br /><br /><a href="URL" rel="bookmark">link title</a><br /><br />, etc....
这是我希望jCarousel文本滚动条显示的html。您似乎错过了启动旋转木马的实际调用 html需要包装在一个div中
<div id="mycarousel">
<a href="URL" rel="bookmark">link title</a><br /><br />
<a href="URL" rel="bookmark">link title</a><br /><br />, etc....
</div>
在
此方法需要将WP php文件名替换为特殊的_textcoller.php
或者可以使用WP函数更改特殊的_textcroller.php
同样,仅当您不想更改其他jCarousel函数时,才需要通过XML格式发送输出 为了清晰起见,我在页面主体中添加了HTML代码;我想弄明白的是如何让jCarousel使用PHP函数生成的URL列表,而不是原始函数中的XML提要
jQuery('#mycarousel').jcarousel({
vertical: true,
size: 0,
initCallback: mycarousel_initCallback
});
function mycarousel_initCallback(carousel, state){
carousel.lock();
jQuery.get(
'special_textscroller.php',
{
'feed': 'http://jquery.com/blog/feed/atom/'
},
function(xml) {
mycarousel_itemAddCallback(carousel, xml);
},
'xml'
);};