【问题标题】:Wordpress post sliderWordPress 帖子滑块
【发布时间】:2013-11-12 21:38:36
【问题描述】:

所以我想做的是有一个 wordpress 内容区域,当点击链接时会显示下一篇文章。我有这个作为我的帖子查询

<?php
$args = array();
$lastposts = get_posts( $args );
foreach ( $lastposts as $post )
{
  setup_postdata( $post );
  $posts[] += $post->ID;
}
$current = array_search(get_the_ID(), $posts);
$prevID = $posts[$current-1];
$nextID = $posts[$current+1];

?>

然后我把这个作为分页链接

<?php if (!empty($prevID)) { ?>
    <li class="previous">
    <a class="panel" href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">&larr; Older</a>
    </li>
 <?php }
 if (!empty($nextID)) { ?>
    <li class="next">
    <a class="panel" href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Newer &rarr;</a>
    </li>
 <?php } ?>

我不知道如何告诉帖子的内容(the_permalink、the_content)来显示下一个帖子。我的目标是添加某种过渡,但这并不像出现下一篇文章那么重要。有什么想法,有可能吗?

【问题讨论】:

  • 感谢您的回答。不知道为什么有人会降级我的问题,但无论如何。这类似于我现在使用的滑块功能,问题是让 wordpress 识别下一张幻灯片应该包含下一篇文章的内容。我将尝试创建一个面具,然后隐藏 5 个元素。然后看看是否将 $nextID 参数添加到 wp_content 函数将起作用。如果有人知道更好的方法,请告诉我。

标签: javascript php jquery wordpress dynamic-data


【解决方案1】:

我一直讨厌旋转木马和滑块,但这个特殊的滑块一直是我的首选,因为它超级简单且非常可定制。

jcarousellite 是它的名字,它雄伟壮观。这是网站http://www.gmarwaha.com/jquery/jcarousellite/

如果你对 css 有基本的了解,你会喜欢这个,但这里有一个示例模型。

<head>
<title>Test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript" src="http://www.gmarwaha.com/jquery/jcarousellite/js/jcarousellite_1.0.1.js"></script>
</head>
<body>
<button class="prev"><<</button>
<button class="next">>></button>

<div class="anyClass">
    <ul>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
        <li><img src="someimage" alt="" width="100" height="100" ></li>
    </ul>
</div>

<script type="text/javascript">
$(function() {
    $(".anyClass").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });
});
</script>
</body>

在此,我至少会在您的服务器上托管 jcarousellite.js 文件,因为那里有很多设置可以玩,比如一次显示 1 张图像,但我希望这对您有所帮助!别忘了你可以给按钮添加 id 让它们看起来更漂亮,并用 CSS 包裹所有东西让它看起来很性感。

【讨论】:

    【解决方案2】:

    把中间的li换成这个

    <?php 
      $thumbnails = get_posts('numberposts=5');
      foreach ($thumbnails as $thumbnail) {
        if ( has_post_thumbnail($thumbnail->ID)) {
          echo '<li><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
          echo get_the_post_thumbnail($thumbnail->ID, 'medium');
          echo '</a></li>';
        }
      }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多