【问题标题】:Marquee Recent Posts (Wordpress)选框最近的帖子(Wordpress)
【发布时间】:2014-09-25 03:22:55
【问题描述】:

我使用以下代码在 Wordpress 中显示最近的帖子,并在 Marquee 中显示日期和时间戳。

<script type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    var i = 0;
    $(".marquee").last().addClass("last");
    $(".marquee").each(function() {
          var $this = $(this);
          $this.css("top", i);
          i += $this.height();
          doScroll($this);
    });
});

    function doScroll($ele) {
        var top = parseInt($ele.css("top"));
        if(top < 0) { //bit arbitrary!
            var $lastEle = $(".last");
            $lastEle.removeClass("last");
            $ele.addClass("last");
            var top = (parseInt($lastEle.css("top")) + $lastEle.height());
            $ele.css("top", top);
        }
        $ele.animate({ top: (parseInt(top)-600) },
200,'linear', function() {doScroll($(this))});
    }

</script>

<div id="mholder">

<div class="marquee" style="height: auto">
<a title="<?php echo the_title() ?>" href="<?php the_permalink() ?>">
<?php echo $title_short ?></a><span><small><br/>
<?php the_time('F jS, g:i a') ?></small></span>

</div>

</div>

<style>

.marquee {
    height: 50px
    color: #ccc;
    border: none;
    position:absolute;
}

#mholder {
    height: 600px;
    width: 150px;
    border: none;
    position: absolute;
    overflow: hidden;
}

</style>

我想让它一次只显示 14 个帖子中的 4 个。滚动机制是不规则的,我想让它平滑稳定。 此外,如果有人知道如何显示特定类别的帖子,那将很有帮助。

【问题讨论】:

    标签: javascript php wordpress post marquee


    【解决方案1】:
    <head>
    <script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
    </head>
    <body>
    
    <div class="newsblock">
    
    <ul id="newgall">
    <?php
    //display 12 posts with title and date
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'post_category' => '123',
      'posts_per_page' => 12,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    
      while ($my_query->have_posts()) : $my_query->the_post(); 
    ?>
    
        <li>
        <p>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
        <br/><?php the_time('F jS, g:i a') ?>
        <br/>
        </p>
        </li>
    
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
      </ul>
    </div>          
    <script>
            var $items = $('#newgall li'),
                i = 0;
    
            function slide() {
                var index = i % $items.length;
                $items.hide().removeClass('curr').slice(index, index +4).show('fade').addClass('curr');
                i += 4;
                setTimeout(slide, 400);
            };
    
            slide();
    </script>
        </body>
    

    有效。享受吧,互联网

    【讨论】:

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