我仍然在學習PHP和jQuery,這對我來說似乎是一件相當複雜的事情。如何使用jCarousel和PHP函數?
我想要做的就是使用jCarousel的textscroller功能來顯示由PHP函數生成的URL列表,而不是jCarousel寫入的XML提要和URL。 (演示:http://sorgalla.com/projects/jcarousel/examples/special_textscroller.html)
我想要使用的WordPress PHP函數生成一些URL標記,其中包含某些WordPress標記的某些或所有帖子在WordPress類別中的列表。
因此,我認爲我不需要jCarousel的XML函數或html創建者函數,也不需要截斷字符串。
那麼,是否有可能在jQuery函數中包含PHP函數,或者我是否有jQuery函數從PHP函數中檢索URL列表,類似於向jCarousel提供XML提要?我需要使用jQuery-PHP庫嗎? http://jquery.hohli.com
任何答案將不勝感激。 - 馬克
這是使用XML飼料的jCarousel功能:(我省略文件準備功能)
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代碼;我想弄清楚的是如何讓jCarousel使用PHP函數生成的URL列表,而不是原始函數中的XML提要 – markratledge 2009-07-06 17:46:10