将Jcarousel集成到wordpress中以显示相关帖子

时间:2011-08-28 23:12:53

标签: wordpress jcarousel

我正在尝试使用jcarousel来显示可以滚动的相关帖子,我用来显示相关帖子的代码是:

$orig_post = $post;
global $post;

$tags = wp_get_post_tags($post->ID);
if ($tags) {
    $tag_ids = array();
    foreach($tags as $individual_tag)
        $tag_ids[] = $individual_tag->term_id;
    $args = array(
        'tag__in' => $tag_ids,
        'post__not_in' => array($post->ID),
        'posts_per_page'=>4, // Number of related posts that will be shown.
        'caller_get_posts'=>1,
        'post_type'=>'books'
    );
    $my_query = new wp_query( $args );
    if( $my_query->have_posts() ) {
        while( $my_query->have_posts() ) {
            $my_query->the_post(); ?>
            <ul id="mycarousel" class="jcarousel-skin-tango">
                <li>
                    <div class="relatedthumb">
                        <a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
                    </div>
                </li>
        <? }
        echo '</ul></div>';
    }
} else {
    echo 'No Related Posts Found';
}
$post = $orig_post;
wp_reset_query();

和初始化jcarousel的代码是:

<script type="text/javascript" src="../lib/jquery-1.4.2.min.js"></script>
<!--
  jCarousel library
-->
<script type="text/javascript" src="../lib/jquery.jcarousel.min.js"></script>
<!--
  jCarousel skin stylesheet
-->
<link rel="stylesheet" type="text/css" href="../skins/tango/skin.css" />

<script type="text/javascript">

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel();
});

</script>

此代码仅在我有静态无序列表时才有效。但是当我动态调用列表项时,它不起作用。请帮我解决这个问题。

我下载Jcarousel页面的链接是http://sorgalla.com/jcarousel/他们有关于如何加载动态内容的示例,但我不认为他们的任何示例都适用于我的问题,所以我非常感谢您的帮助。< / p>

编辑: 没关系。我自己想出来了。

<ul id="mycarousel" class="jcarousel-skin-tango">

在错误的地方应该在相关的邮政编码之前调用它。

0 个答案:

没有答案