我使用以下代码在Wordpress中显示带有日期和时间戳的Wordpress中的最新帖子。
<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个。滚动机制是不规则的,我想使它平滑和稳定。 此外,如果有人知道如何显示特定的类别帖子,那将会有所帮助。
答案 0 :(得分:0)
<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>
作品。享受,互联网!