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

发布于 2024-12-01 17:31:18 字数 2120 浏览 0 评论 0原文

我正在尝试使用 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/ 他们有关于如何使用的示例加载动态内容,但我认为他们的任何示例都不适用于我的问题,所以我将非常感谢您的帮助。

编辑: 没关系。我自己想出来了。我把它放在了

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

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

I am trying to use jcarousel to show related posts that can be scrolled through, the code I'm using to show related posts is:

$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();

and the code to initialize jcarousel is:

<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>

This code works only when I have a static unordered list. But when I am calling the list items dynamically it doesn't work. Please help me sort this out.

The link to the page I downloaded Jcarousel is http://sorgalla.com/jcarousel/ they have examples on how to load dynamic content but I don't think any of their examples apply to my question, so I would greatly appreciate your help.

Edit:
Nevermind. I figured it out on my own. I had the

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

in the wrong place it should have been called right before the related post code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文